Tuesday, June 25, 2013

Show Random Posts Wordpress


You can show Random Posts on your WordPress site with very simple code.

Just add the following code on single.php where you want to show the Random Posts in wordpress


<div class="related_post">
      <?php 
echo '<h3>Random Posts</h3>';
$posts = get_posts('orderby=rand&numberposts=5');
foreach($posts as $post) :
?>
      <div class="rp">
        <li><a href="<?php the_permalink() ?>">
          <?php the_post_thumbnail(array(120,120)); ?>
          </a>
          <h4><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
            <?php the_title(); ?>
            </a></h4>
        </li>
      </div>
      <?php
wp_reset_query(); 
endforeach;
?>
    </div>
  </div>

No comments:

Post a Comment