Posted By

wpCanyon on 11/17/10


Tagged

wordpress


Versions (?)

Showing Random Posts In WordPress


 / Published in: PHP
 

URL: http://wpcanyon.com/tipsandtricks/showing-random-posts-in-wordpress/

  1. function randomPosts($numPosts = 5){
  2.  
  3. query_posts(array('orderby' => 'rand', 'showposts' => $numPosts));
  4. ?> <ul> <?php
  5. if (have_posts()) : while (have_posts()) : the_post();
  6.  
  7. ?>
  8. <li><a title="Permanent Link to <?php the_title(); ?>" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
  9.  
  10. <?php
  11.  
  12. endwhile;
  13.  
  14. ?> </ul> <?php
  15.  
  16. endif;
  17.  
  18. wp_reset_query();
  19.  
  20. }

Report this snippet  

You need to login to post a comment.