Share Pastebin
Guest
Public paste!

kuld33p

By: a guest | Jul 4th, 2009 | Syntax: None | Size: 0.69 KB | Hits: 231 | Expires: Never
Copy text to clipboard
  1. <div class="entry page">
  2.                 <h2>Related Posts</h2>
  3.        
  4.                 <?php
  5. //for use in the loop, list 5 post titles related to first tag on current post
  6. $tags = wp_get_post_tags($post->ID);
  7. if ($tags) {
  8.   $first_tag = $tags[0]->term_id;
  9.   $args=array(
  10.     'tag__in' => array($first_tag),
  11.     'post__not_in' => array($post->ID),
  12.     'showposts'=>5,
  13.     'caller_get_posts'=>1
  14.    );
  15.   $my_query = new WP_Query($args);
  16.   if( $my_query->have_posts() ) {
  17.     while ($my_query->have_posts()) : $my_query->the_post(); ?>
  18.       <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
  19.       <?php
  20.     endwhile;
  21.   }
  22. }
  23. ?>
  24. </div>