Comment And Ping Count In WordPress 2.7

The comment area changed a lot in WordPress 2.7. A good reason to check your comments.php and make some changes to it. Especially I like to seperate the comments from Ping- and Trackbacks. Matt shows in an excellent tutorial how to do it: Separating Pings from Comments.

But I didn’t like one thing in this tutorial. To show the total count of your comments without Pings/Trackbacks, he writes following function in functions.php:

This filter will assign globally of course. But in our blog right under the post title we have the number of comments displayed. If there is no comment but for example 2 Pingbacks, it still shows 0 comments, even though Pingbacks are kind of a comment.

The Solution


The same for Pings and everything is perfect. ๐Ÿ™‚





16 responses to “Comment And Ping Count In WordPress 2.7”

  1. Jared Avatar

    Thanks for the Snippet ๐Ÿ˜‰
    I use a Variation for my tweetbacks.

  2. Peter Zhang Avatar

    Really helpful. Thanks!

  3. WPCult Avatar

    I need to apply this to my current theme. I hacked the comments to split the comments and ping, but didn’t change the counter..

  4. Michael Avatar

    WPCult, did you use Matt’s code? Than you dont have to use his function comment_count(). Delete that function and use my code in the comments.php

  5. Greg Mulhauser Avatar

    And if you’d like to number your comments one by one so the numbers will still work even with date order reversed, even with paging enabled, and even with threading enabled, there’s a handy new plugin (shameless plug, cough splutter, ahem) which will do the trick:

    Greg’s Threaded Comment Numbering

    Very handy, IMHO…

    All the best,
    Greg (yup, the plugin guy)

  6. Alex Avatar

    Hey Greg, thanks for your plugin, I’m sure, many people will use it.

  7. Goedkope Avatar

    WordPress 2.7 has introduced many new features surrounding comments. Of these is AJAX commenting and threaded comments. To take advantage of the later, you must use a function wp_list_comments instead of the old way of looping through the comments array with a foreach.

  8. Vittorio Avatar

    Hi Michael,
    your snippet seems exactly what I was looking for, but I can’t understand where I should put your code and how I could do “the same for Pings”, could you please explain it?

    Basically, what I need is only to display something like “This post has 3 comments and 2 pings” for each article: has this anything to do with the comments_popup_link function?


  9. Michael Avatar

    @Vittorio: The code has nothing to do with the comment_popup_link function. Its a part of comments.php. For the Ping part you can use

    if ( ! empty($comments_by_type['pings']) ) :
        $count = count($comments_by_type['pings']);
        ($count !== 1) ? $txt = "Pings" : $txt = "Ping"; ?>

  10. Vittorio Avatar

    Thanks Michael for your quick reply.

    I understand this code has to go in comments.php, and I added it just below the same snippet for normal comments, as you pointed in your post.

    Btw, my problem is still unsolved: how can I display, for each article in the frontpage, 2 separate counts, like “This post has X comments and Y pings”?

    Sorry to bother, and thank you again ๐Ÿ™‚

  11. Pomy Avatar

    I want to show the total no. of comments from intense debate into footer like
    Total Comments : 56 ( or Whatever)
    how can I achieve this while I’m using the intense depate plugin..
    Note: I don’t want to use intense debate widget… I want to get it manually into my template…

    Any Idea?


  12. Pomy Avatar

    @ Michael…
    Sorry to say…you did not understand my question… I’m repeating..
    I don’t want to show the wordpress own comments which made from template..but im using intense debate plugin for making comments (
    So, I want to show the total comments which people made from intense debate… like
    total comments from intense debate plugin = 156
    I hope you can understand what I’m asking
    Here is a screenshot for better understand..

    Hope you’ll guide me again..Thanks

  13. Michael Avatar

    @Pomy: Sorry, i don’t have intense deate. Can’t help ya.

  14. Website laten maken Avatar

    @Jared: Please explain.

  15. ARS Avatar

    Hi, I’m looking for the tricks to show comment lists numberization (not to show total comments) just like yours. so in each comment box, it will show 1, 2, 3, 4, 5, etc…

    Can you tell me the code please?

    *sorry for my bad english*