Advertisement
alchymyth

related posts by tag

Jun 3rd, 2011
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.13 KB | None | 0 0
  1. <section class="similar">
  2.     <h4>Similar</h4>
  3.     <ul class="posts">
  4.     <?php
  5.         $tags = wp_get_post_tags($post->ID);
  6.         if ($tags) {
  7.             foreach( $tags as $tag) { $first_tag[] = $tag->term_id; } //NEW
  8.             $s_args=array(
  9.                 'category_name'         => parent_category(),
  10.                 'tag__in'               => $first_tag, //NEW CHANGE
  11.                 'post__not_in'          => array($post->ID),
  12.                 'showposts'             => 4,
  13.                 'caller_get_posts'      => 1
  14.             );
  15.         $similar = new WP_Query($s_args);
  16.             $not_to_dupe = array($post->ID); //NEW
  17.         if ($similar->have_posts()) {
  18.             while ($similar->have_posts()) : $similar->the_post();
  19.             $not_to_dupe[] = $post->ID; //NEW
  20.                 get_template_part('loop', '');
  21.             endwhile;
  22.         };
  23.     }; ?>
  24.     </ul>
  25. </section>
  26.  
  27. <section class="popular">
  28.     <h4>Popular</h4>
  29.     <ul class="posts">
  30.         <?php
  31.             $p_args = array(
  32.                 'category_name'         => parent_category(),
  33.                 'orderby'               => 'comment_count',
  34.                 'post__not_in'          => $not_to_dupe, //NEW
  35.                 'posts_per_page'        => 4
  36.             );
  37.             $popular = new WP_Query($p_args);
  38.             while ($popular->have_posts()) : $popular->the_post();
  39.                 get_template_part('loop', '');
  40.             endwhile;
  41.         ?>
  42.     </ul>
  43. </section>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement