Showing Random Posts In WordPress


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.