Display random post in Wordpress
Display random post in Wordpress.
We can display random post with orderby=rand command, for example :
query_posts('tag=whatever&showposts=5&offset=0&orderby=rand');
<ul class="random-posts">
<?php query_posts('tag=whatever&showposts=5&offset=0&orderby=rand'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endwhile; endif; ?>
</ul>
For those of you who would like to setup some random post loops on your own site, here’s how to do it in two easy steps. (Remember, this is only necessary if the above method does not work for your particular version of WordPress.)
Related posts: