Display Random Posts In WordPress

By -

Sometimes in your theme you want to display random posts or maybe random related posts in your sidebar,

here’s an easy way to do it.

in your single.php or index.php, change the main loop to:


query_posts(array('orderby' => 'rand', 'showposts' => 1)); 
if (have_posts()) : while (have_posts()) : the_post(); ?> 
<h1><a href="<?php the_permalink() ?>">
<?php the_title(); ?></a></h1> <?php the_content(); ?> 
<?php endwhile; endif; ?>

WordPress is a full featured Content Management System (CMS). It has incorporated a rich suite of capabilities that have proven to be extremely popular because it allows anyone to create vibrant, dynamic sites without any programming knowledge. Its large range of features, coupled with a clean and easy-to-understand interface make it a fan fave among website novices; 27% of all the websites in existence and 20% of all new ones use this amazing platform.

Leave a Reply

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

Human test: *