WordPress display random posts

Following code will display a list of 5 posts selected randomly by using the MySQL RAND() function for the orderby parameter value:

 <ul><li><h2>A random selection of our Posts</h2>
 <ul>
 <?php
 $rand_posts = get_posts('numberposts=5&orderby=rand');
 foreach( $rand_posts as $post ) :
 ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
 <?php endforeach; ?>
    </ul>
 </li></ul> 

Leave a Reply

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

2 Comments

  1. random post to display a specific category as I do? gracias