• On my site I’ve created a couple of lists of posts which are filtered by category or which filter out a category. I seem to be running into some difficulty with these. There are 2 blocks of very similar code giving me very different results.

    Code sample 1:

    <?php if (!is_home()) { ?>
    		<ul>
    		<?php
    		 global $post;
    		 $myposts = get_posts('numberposts=5&category=4');
    		 foreach($myposts as $post) :
    		 ?>
    		<li><b><a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></a><b><br /> <div class="altPostMeta"><?php the_time('j M Y') ?> || <?php comments_popup_link('Share your own memories', 'Read what someone said about this', '% others have commented. Add yours.'); ?></div></li>
    		 <?php endforeach; ?>
    		</ul>
    <?php } ?>

    This portion filters according to one category (category 4). It is featured on internal pages as-is, and on the front page (using php if (is_home()) {…}) with “get_posts(‘numberposts=5&offset=1&category=4’);” because the front page displays only one post at a time, from Category 4.

    The problem is with the “comments_popup_link( )” portion. In the front page, no matter the number of comments in the article, only the first parameter (“Share your own memories”) is displayed. (Note that all the links go to their respective stories, however: it’s just the number of comments which don’t register.) Furthermore, in internal pages, none of the parameters are displayed: it’s just a blank space!

    Strangely, right below it is the following code:

    <ul><?php
    		 $lastposts = get_posts('numberposts=5&category=-4');
    		 foreach($lastposts as $post) :
    		    setup_postdata($post);
    		 ?>
    		<li><b><a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></a><b><br /> <div class="altPostMeta"><?php the_time('j M Y') ?> || <?php comments_popup_link('Start a conversation', 'Join the conversation', 'Read what % others thought'); ?></div></li>
    		<?php endforeach; ?>
    		</ul>

    In the front page, the comments_popup_link( ) displays all parameters properly. In internal pages, however, none of the parameters are displayed. Like with the first code sample, there’s only a blank space.

    So my question is (1) why is this happening, and (2) how can I fix it. I’m guessing that in the front page, the filter is interfering with the first bit of code, although I don’t understand how. With the internal pages… I’m at a complete loss.

    Thanks in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter gnorb

    (@gnorb)

    Actually, i found out why comments_popup_link doesn’t work on pages here. Still Wondering about the first page, though.

    Thread Starter gnorb

    (@gnorb)

    Alright, I figured out one piece of the puzzle: The “comments_popup_link” for the first snippet of code is reading the comments status of the stuff in the main loop. There, only one article is displayed, of the same category (category 4) as the code snippet. The second code snippet filters OUT category 4, so for it that’s neither here nor there.

    My question: is “comments_popup_link” dependent on the main loop to gather its information? Is there another call I could make that would give me the total number of comments?

    Thanks in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Sidebar list of posts only sometimes detects the number of comments’ is closed to new replies.