SHARE
TWEET

Untitled

a guest Oct 17th, 2011 24 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <h2>Related Posts</h2>                      
  2.  
  3. <!-- "previous page" action -->
  4. <a class="prev browse left"></a>
  5.  
  6. <?php
  7.  
  8.  $tags = wp_get_post_tags($post->ID);
  9.  if ($tags) {
  10.      $tag_ids = array();
  11.      foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
  12.  
  13.  $args=array(
  14. 'tag__in' => $tag_ids,
  15. 'post__not_in' => array($post->ID),
  16. 'showposts'=>12, // get all the posts at once, then split them up afterwards.
  17. 'ignore_sticky_posts' => 1
  18.  );
  19.  
  20. $posts_per_block = 4;
  21.  
  22. $my_query = new wp_query($args); ?>
  23.  
  24. <!-- root element for scrollable -->
  25. <div class="scrollable" id=chained>  
  26.  
  27.     <!-- root element for the items -->
  28.     <div class="items">
  29.  
  30. <?php
  31. if( $my_query->have_posts() ) : while ($my_query->have_posts()) : $my_query->the_post();
  32. if ( ($my_query->current_post) == 0 ) {
  33.     echo '<div>';
  34. }
  35. elseif ( ( $my_query->current_post ) % $posts_per_block == 0 ) {
  36.     echo '</div><div>'; //close and open a new div every nth post
  37. }
  38. ?>
  39.  
  40. <div class="relatedPosts"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_post_thumbnail(array(120,80)); ?></a>
  41. <div class="relatedPosts_title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></div></div>
  42.  
  43. <?php
  44.  
  45. if ( ( $my_query->current_post + 1) == ( $my_query->post_count ) ) {
  46.     echo '</div>'; //close the block if you run out of posts
  47. } ?>
  48.  
  49. <?php
  50. endwhile; endif;
  51. ?>
  52.  
  53.     </div>
  54.  
  55. <?php } // end if($tags) ?>
  56.  
  57. </div>
  58.  
  59. <!-- "next page" action -->
  60. <a class="next browse right"></a>
  61.  
  62.  
  63.  
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top