X

Display user comment count next to username

ThirstyAffiliates Review - add new link

Add the first snippet into the functions.php of your wordpress theme. Open up your comments.php template and place the second snippet commentCount() in the location you wish to display each users comment count.


<?
function commentCount() {
    global $wpdb;
    $count = $wpdb->get_var('SELECT COUNT(comment_ID) FROM ' . $wpdb->comments. ' WHERE comment_author_email = "' . get_comment_author_email() . '"');
    echo $count . ' comments';
}
?>
<?php 
            commentCount(); 
?>

Comments  Leave a Reply

  1. Add the first snippet to the functions.php of your wordpress theme, then add the second snippet in the location you want to display the comment count. The place you may want to add it would be beside the users name “comment_author()” you should see that line within your comments.php.

  2. Hi!
    I want to display name of the user who is currently logged in and after logs out his name should be with the comment.
    i’ve used session but when i logout the session destroys an dthe name and the comment disappears because of unsetting the session.
    Thank You!

  3. mlmleadsgenerationblog May 16, 2013 at 10:46 pm

    Hi Kevin, thank you for this tutorial 🙂

    I was wondering…do you know how to add the comment for each user as a sortable column in the Admin panel (the user list)?

    Thank you in advance for your help,
    Roselle

  4. How would you use Transients API with this to cache it? #wordpress

    1. Sent you a link to a great post about this via twitter.

  5. BlackBerry Empire April 12, 2011 at 10:25 pm

    is this only for disqus system?

    1. No this is not just for disqus, should work with any wordpress themes.

  6. BlackBerry Empire April 12, 2011 at 10:24 pm

    I dont see comment author on either comments.php

  7. BlackBerry Empire April 12, 2011 at 10:16 pm

    I am trying to get it in the skeleton theme of wptouch

    1. I have never used that theme but if you add the commentCount() within the comment loop comments should be displayed within a unordered list. It will work, I would have to see the theme file to be sure. Use http://pastebin.com/ to post your code if you wish,

  8. BlackBerry Empire April 12, 2011 at 10:13 pm

    I dont see comment_author

  9. BlackBerry Empire April 12, 2011 at 8:52 pm

    where do we add it?

    1. Add the first snippet to the functions.php of your wordpress theme, then add the second snippet in the location you want to display the comment count. The place you may want to add it would be beside the users name “comment_author()” you should see that line within your comments.php.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!