Advertisement
Guest User

Stackoverflow

a guest
Jul 8th, 2016
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.94 KB | None | 0 0
  1.  <?php $orig_post = $post;
  2. global $post;
  3. $tags = wp_get_post_tags($post->ID);
  4. if ($tags) {
  5. $tag_ids = array();
  6. foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
  7. $args=array(
  8. 'tag__in' => $tag_ids,
  9. 'post__not_in' => array($post->ID),
  10. 'posts_per_page'=>5, // Number of related posts that will be shown.
  11. 'caller_get_posts'=>1
  12. );
  13. $my_query = new wp_query( $args );
  14. if( $my_query->have_posts() ) {
  15. echo '<div id="relatedposts"><h3>Related Posts</h3><ul>';
  16. while( $my_query->have_posts() ) {
  17. $my_query->the_post(); ?>
  18. <li><div class="relatedthumb"><a href="<? the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_post_thumbnail(); ?></a></div>
  19. <div class="relatedcontent">
  20. <h3><a href="<? the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3>
  21. <?php the_time('M j, Y') ?>
  22. </div>
  23. </li>
  24. <? }
  25. echo '</ul></div>';
  26. }
  27. }
  28. $post = $orig_post;
  29. wp_reset_query(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement