Ping/Track/Comment Count

About

This plugin, co-created by Chris J. Davis, Scott Merrill, and Mark Jaquith in one magical rainbow-filled night contains two functions that return and echo the number of pingbacks, trackbacks, combined pings or regular comments for a WordPress entry.

This is of particular use to people who want to separate their regular comments from their pings. The plugin is “smart” and will grab all the numbers in one go the first time you call it, so that subsequent calls use no database queries, making it very efficient.

Download

Usage

There are two functions you can use: get_comment_type_count() (which returns the value) and comment_type_count() (which echoes the value).

Both functions operate identically, and take 2 optional parameters. The first parameter is the type of comment you would like returned (defaults to ‘all’). Your options are trackback, pingback, ping, and comment.

For example, pretend that a post has 1 pingback, 2 trackbacks, and 4 regular comments.

<?php
comment_type_count('pingback'); // prints "1"
comment_type_count('trackback'); // prints "2"
comment_type_count('ping'); // prints "3" (1 pingback + 2 trackbacks)
comment_type_count('comment'); // prints "4"
comment_type_count(); // prints "7" (1 pingback + 2 trackbacks + 4 comments)
?>

The second parameter, which is also optional, is a post ID. By default, the function just gives you the number for the current post being processed in “the loop.” By passing a specific post ID, you can get the count for any post ID you wish.

<?php
comment_type_count('pingback', 534); // prints number of pingbacks on entry 534
?>

I’ve spent a lot of time writing this code and supporting it. If you derive some benefit from this code, please consider showing your gratitute in a more tangible
way. Thanks!

I have received $0 this month for my coding efforts.

Donate with PayPalAmazon.com Wishlist


61 Responses to “Ping/Track/Comment Count”

  1. Micha |

    Source Code couldn’t be displayed. :(

  2. Mark (post author) |

    Micha, just moved to a new server. Thanks for pointing that out. I’ll try and get that fixed.

  3. Mark (post author) |

    Alright, it should be fixed now!

  4. Micha |

    It is fixed. :)

  5. bangbang023 |

    When I added the code to my post.php file, it limited my index to one post per page. Is there a way to solve this? This seems to be the only working plugin to so all of this, right now.

  6. Mark (post author) |

    Did you get an error? The only reason I can think that it would limit it to one post is if there was an error and it stopped outputting the page after that. Let me know what the error was and I’ll look into it.

  7. bangbang023 |

    No, unfortunately, there was no error outputted

  8. Mark (post author) |

    You sure? You viewed the source of the page and looked at the place where the function is called and there was no error?

  9. bangbang023 |

    No error at all. There’s not even a whitespace in the source where the function is being called.

  10. John Cass |

    Hi, does this mean that I can count the number of trackbacks, and comments on another blog?

    John

  11. John Cass |

    Hi, sorry I understand your plugin is for the an individual blog, my real question is this, how would I count comments or trackbacks on another blog without having to do it manually?

  12. Mark (post author) |

    You can’t. You’d need access to their database.

  13. Madthiu |

    Hi, I am having problem with this great plugin. When I activate it in my WP2.0 plugin page, the following message shown above my admin page header after the plugin page is reloaded:

    Warning: Cannot modify header information - headers already sent by (output started at /home/.fenestra/madthiu/blog/wp-content/plugins/ping-track-comment-count.php:81) in /home/.fenestra/madthiu/blog/wp-admin/plugins.php on line 16

    And it makes one of my plugin, the LiveCalendar not working. Everything back to normal when “Ping/Track/Comment Count” is disabled. May I know if there is anything I can modify in my blog to solve the conflict? (Except disabling LiveCalendar)

    Thank you.

  14. Mark (post author) |

    You must have an extra space after the closing ?> in the plugin … make sure there is no space after that.

  15. Madthiu |

    Yeah~! It’s fixed, thanks~!! :D

  16. John Cass |

    Thanks Mark, makes sense.

  17. Mark |

    just wondering where to put this code. as i can’t find the post.php file

  18. Mark (post author) |

    Within the WordPress loop would be the best location.

  19. Tom Edwards |

    Thanks, that’s exactly what I was looking for! In fact there’s quite a lot of stuff you’ve got here that I’d like to ‘borrow’; could you please point me towards the plugin/tag/whatever for the Blog Author/Subscribed buttons you’re using? Thanks again. :-)

  20. Jan |

    Seems that it doesn’t work with Wordpress 2.0.3. I get an error about already send headers everytime I try to save a document and the default WYSIWYG Editor is gone.

  21. Jan |

    I always get the following error message after activating this plugin:
    Warning: Cannot modify header information - headers already sent by (output started at wp-content/plugins/count_trackbacks.php:64) in wp-includes/pluggable-functions.php on line 272

    Does somebody know it? Or better does somebody know how to fix it?

  22. Will |

    Hi,

    [quote]When I added the code to my post.php file, it limited my index to one post per page. Is there a way to solve this? This seems to be the only working plugin to so all of this, right now.[/quote]

    I am getting the same thing! :( No errors of any kind either.

    Also, for your example how can I make it output:

    1 pingback
    2 trackbacks
    3 pings
    4 comments

    Take Care,

    Will

  23. ivaeej |

    Hi My Name Is ivatut.

  24. Brytney |

    Your site is perfect!

  25. Seb |

    Nice! I’ll definately check back here!

  26. Andrew Hopkins |

    I can do a blog on your website? how much it will cost?

  27. Visitor765 |

    I have visited your site 116-times

  28. Visitor892 |

    I could not find this site in the Search Engines index

  29. DDT-WEBKINZ |

    I thought that the WTO would be a good start for transforming the process of government at least across national borders. I quite like the idea of using the secretariat of the WTO as the centre for a Wikipedia of trade - a sort of open source world government at least for a very specific and complicated issue which needs many brains to provide a solution.

  30. Stasigrii |

    Hello, very nice site, keep up good job!
    Admin good, very good.

  31. poer |

    hi, thanks for the code, very handy to help me separate my pings and comments.

  32. Exingupeillep |

    College degree will be an advantage.
    # Have a minimal experience and knowledge of basic bank operations.
    # The ability to operate with more than one task effectively,
    and have an adaptable, flexible, professional attitude
    # The ability of stable communication with
    our company and on-time and detailed reporting.
    blog interview job
    hsbc job offshore putrajaya vacancy
    http://volny.cz/jjob - job online training
    job opportunity physician
    free interview job tip
    http://volny.cz/jjob/map.html - center job mississippi win

Leave a Reply