Solution
Place the code bellow in functions.php file inside your theme’s folder.
function randomPosts($numPosts = 5){
query_posts(array('orderby' => 'rand', 'showposts' => $numPosts));
?> <ul> <?php
if (have_posts()) : while (have_posts()) : the_post();
?>
<li><a title="Permanent Link to <?php the_title(); ?>" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php
endwhile;
?> </ul> <?php
endif;
wp_reset_query();
}
Change the layout to fit your needs.
Calling randomPosts(); will show 5 random posts and if you want a different amount then call it like randomPosts(number);
Our WordPress themes
We have a few WordPress themes that we would like you to take a look at if you want.
check out the portfolio











I like this article.
It is worth mentioning that calling wp_reset_query(); is very important because it “could” mess with the post that is displayed on the page. I encountered this issue on my own site.
Yup, i had that problem some time ago when i was showing related articles before comments and it was showing comments from a different post
Then i found out i need to reset the query.
Thanks for this. It’s a good alternative to installing a random posts plugin.
ESN – You’re welcome
Thank you, I tried in my blog, But it failed due to the index pages width, My sidebar was moved below the footer, Im using Fresh Life theme from themejunki,
any support would be appriciated