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);
Visit the best themes marketplace with over 600 premium wordpress themes.













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