Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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>';
   }
share|improve this question
    
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
add comment

1 Answer

up vote 0 down vote accepted

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 ).

share|improve this answer
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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