WordPress Random Post function (List, URL, ID)

This Snippet create a list of Random Posts

<?php query_posts('showposts=5&orderby=rand');
while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>

This Snippet create a URL from a Random Post

<?php query_posts('showposts=1&orderby=rand');
while (have_posts()) : the_post(); ?>
<?php the_permalink() ?>
<?php endwhile; ?>

This Snippet create the ID from a Random Post

<?php query_posts('showposts=1&orderby=rand');
while (have_posts()) : the_post(); ?>
<?php the_ID() ?>
<?php endwhile; ?>

Leave a Reply