Posted By

iende on 02/02/11


Tagged

wordpress


Versions (?)

Related Posts problem


 / Published in: PHP
 

URL: http://www.ladetentegenerale.com/blog/la-playlist-du-dimanche-23/

Comments are not working properly after adding the rel_box div. The comments displayed are the ones from the last related post.

Can't figure out why. Check above link to see it on the website.

  1. <?php get_header(); ?>
  2.  
  3. <div id="content">
  4.  
  5. <div id="contentleft">
  6.  
  7. <div class="postarea">
  8.  
  9. <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
  10.  
  11. <div class="posttitle">
  12.  
  13. <h3><?php the_title(); ?></h3>
  14.  
  15. <div class="postauthor">
  16. <p><?php _e("Posted by", 'organicthemes'); ?> <?php the_author_posts_link(); ?> on <?php the_time('l, F j, Y'); ?> &middot; <a href="<?php the_permalink(); ?>#comments"><?php comments_number('Leave a Comment', '1 Comment', '% Comments'); ?></a>&nbsp;<?php edit_post_link('(Edit)', '', ''); ?></p>
  17. </div>
  18.  
  19. </div>
  20.  
  21. <?php the_content(__('Read More'));?><div style="clear:both;"></div>
  22. <?php trackback_rdf(); ?>
  23.  
  24. <div style="margin-top:10px"><script src="http://connect.facebook.net/fr_FR/all.js#xfbml=1"></script><fb:like show_faces="false" width="520" style="margin-right:10px"></fb:like><a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-via="DetenteGenerale">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div>
  25.  
  26. <div class="postmeta">
  27. <p><?php _e("Filed under", 'organicthemes'); ?> <?php the_category(', ') ?> &middot; <?php _e("Tagged with", 'organicthemes'); ?> <?php the_tags('') ?></p>
  28. </div>
  29.  
  30. </div>
  31.  
  32. <div class="rel_box">
  33. <?php
  34. $tags = wp_get_post_tags($post->ID);
  35. if ($tags) {
  36. $first_tag = $tags[0]->term_id;
  37. $args=array(
  38. 'tag__in' => array($first_tag),
  39. 'post__not_in' => array($post->ID),
  40. 'showposts'=>4,
  41. 'caller_get_posts'=>1
  42. );
  43.  
  44. $rel_posts = new WP_Query($args);
  45. if( $rel_posts->have_posts() ) {
  46. while ($rel_posts->have_posts()) : $rel_posts->the_post(); ?>
  47.  
  48. <div class="rel_posts">
  49. <div class="rel_thumb"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail(array(145,145)); ?></a></div>
  50. <div class="rel_link"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></div>
  51. </div>
  52. <?php
  53. endwhile;
  54. }
  55. }
  56. ?>
  57.  
  58. <div class="clearer"></div>
  59. </div>
  60.  
  61. <div class="postcomments">
  62. <?php comments_template('',true); ?>
  63. </div>
  64.  
  65. <?php endwhile; else: ?>
  66. <p><?php _e("Sorry, no posts matched your criteria.", 'organicthemes'); ?></p>
  67. <?php endif; ?>
  68.  
  69. </div>
  70.  
  71. <?php include(TEMPLATEPATH."/sidebar_right.php");?>
  72.  
  73. </div>
  74.  
  75. <!-- The main column ends -->
  76.  
  77. <?php get_footer(); ?>

Report this snippet  

You need to login to post a comment.