Support » Themes and Templates » Count comments for each post

  • honeyjazz

    (@honeyjazz)


    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?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Kafkaesqui

    (@kafkaesqui)

    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; ?>

    honeyjazz

    (@honeyjazz)

    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!!

    Kafkaesqui

    (@kafkaesqui)

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

    honeyjazz

    (@honeyjazz)

    Me too 😉

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Count comments for each post’ is closed to new replies.