DISCLAIMER: this post is older than one year and may not be up to date with latest WordPress version.

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:

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

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

One Comment

  1. I want to do something similar, but I’d like to have a button on a specific page template that, when clicked, displays another random post in replacement of whatever is there when they land on the page. I am trying to achieve a “random post” puller within a page without making the user reload the page, or using a link to reload the page. I want it to happen within the same page load.

    Any thoughts? Thanks in advance.

Leave a Comment

Your email address will not be published. Required fields are marked *