Count comments for each post (5 posts)

  1. honeyjazz
    Posted 11 years ago #

    I want to count and display the comments for every single entry.
    I tried it with comment_ID() but that seems to count ALL comments in my blog. (Example: http://www.honeyjazz.net/blog/?p=5#comments).

    Is there a way to modify the template to let the comments be counted for single posts?

  2. Kafkaesqui

    Posted 11 years ago #

    I'm a little confused by your request, but I assume from the link you provided you're just trying to display ascending numbers beside each comment.

    The simplest method is to count off comments with your own variable, and use that to display the #. In commments.php (of your theme -- if it doesn't have one, it will use the one for the default theme), look for this bit of code:

    <?php foreach ($comments as $comment) : ?>

    Just after the foreach, insert your variable with an increment operator:

    <?php foreach ($comments as $comment) : $comment_count++; ?>

    Then where you want your number to display:

    <?php echo $comment_count; ?>

  3. honeyjazz
    Posted 11 years ago #

    YESSS! It works.
    That's exactly what i wanted! :)
    I dind't mean to confuse you but my English is not the best when it come sto technical terms. :/

    Thanks a lot!!

  4. Kafkaesqui

    Posted 11 years ago #

    Don't sweat over the tech language. I hate not fully understanding the question being asked, but I'm glad I assumed correct. :)

  5. honeyjazz
    Posted 11 years ago #

    Me too ;)

Topic Closed

This topic has been closed to new replies.

About this Topic