Display a random post in your wordpress blog sidebar
January 4, 2009 · Print This Article
If you want to display a random post in your wordpress blog sidebar, simply paste the following code on the sidebar.php file of your theme:
<?php
query_posts(array('orderby' => 'rand', 'showposts' => 1));
if (have_posts()) :
while (have_posts()) : the_post();
the_title();
the_excerpt();
endwhile;
endif; ?>
Then your sidebar will display a random post on each of your wordpress blog pages.





















Comments
Got something to say?
You must be logged in to post a comment.