0

I cannot get the comments_popup_link to display with the posts retrieved by the foreach loop. Only the title and permalink are displayed. Any idea why the comment link is left out?

<?php
  if(count($ids)){
    echo '<div id="tab-news" class="tab-all"><a id="link-news" class="link-all" href="/news">News</a></div><ul>';
    foreach($ids as $id){
       echo '<li><a href="'.get_permalink( $id ).'">'.get_the_title( $id ).'</a>';
       if ( comments_open() ) :
       echo '<p>';
       comments_popup_link( '', '<span class="onecomment">1 comment</span>', '<span class="morecomments">% comments</span>', '');
       echo '</p>';
       endif;
    }
    echo '</li></ul>';
   }
  • well, it might be stupidly trivial for me to ask, but do you have comments open on the global site configuration ? or maybe disabled on specific posts ? – krembo99 Feb 27 '12 at 3:29
0

the comments_popup_link() function will only work when used within the_loop; a 'foreach' loop using post Ids is not the same.

you could try to build your own link, based on this function: get_comments_number( $id ).

  • 1
    Thank you! Realized it as well and gave up on the idea and used the normal wordpress loop. The advantage of the foreach loop is that it lets me separate logic and presentation. – sarytash Feb 27 '12 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.