How to: create a page to display a random post

Your blog have probably a lot of posts that your readers haven’t read yet. Why not creating a page and display a random post on it? Here’s an easy way to do it.

The first thing to do is, of course, to create a page template.
Once done, paste the following code in your new page template:

<?php
query_posts(array('orderby' => 'rand', 'showposts' => 1));
if (have_posts()) :
     while (have_posts()) : the_post(); ?>
         // WordPress loop, your random post will appear here
     endwhile;
endif; ?>

That's it! Wonderful way to give a second life to old posts, isn't it?

Leave a Comment

* Name, Email, Comment are Required