How To Show The Amount Of Comments A Comment Author Made

Here is just a small code snippet I found for showing the amount of comments a comment author made.

Here’s a function you can use to get and echo the number of comments a comment author made. It’s pretty easy just put it in the functions.php file in your theme.

function commentCountAuthor(){

	$oneText = 'One comment';
	$moreText = '% comments';

	global $wpdb;

	$result = $wpdb->get_var('
			comment_author_email = "'.get_comment_author_email().'"'

	if($result == 1): 

		echo str_replace('%', $result, $oneText);

	elseif($result > 1): 

		echo str_replace('%', $result, $moreText);



Then just call the function inside the comments loop and shazam! Magic!


30 Responses to How To Show The Amount Of Comments A Comment Author Made

  1. Paul July 10, 2010 at 6:06 am #

    Man, Programming was something that always went above my head. Its good to see great people like you who are helping others by giving us the code to get things working.

    I feel I should be able to put it in my functions.php file.
    Thanks bro

    • Jamie July 10, 2010 at 2:19 pm #

      No problem Paul I’m glad I could help you out:)

      • Bobbie July 12, 2010 at 6:18 am #

        @Jamie, yeah programming is not an easy nut to crack.

        Thanks to people like Jamie who keep helping us out by sharing such awesome stuff!! ;-)

        • Jamie July 12, 2010 at 3:06 pm #

          Thanks Bobbie and You’re welcome I glad I could help!

  2. Michael July 10, 2010 at 6:15 am #

    Hey Paul,

    I agree with you mate…. I’ve been looking for this on google and just reached here.

    I believe whether you put the above code above our existing code or below our existing code in functions.php file, It would still work the same, right Jamie??

    • Jamie July 10, 2010 at 2:48 pm #

      @Michael, That’s correct Michael just make sure you don’t put it in the middle of a another function or block of code.

      • Jessica July 12, 2010 at 6:03 am #

        @Jamie, Yeah, it messes up big time if we paste it in middle of the functions php code.

        It happened to me once with my site. It just stopped working, thank goodness I had created a backup LOL :D

  3. Britney July 10, 2010 at 6:18 am #

    Hey Jamie,

    I really like ur site’s design !!!

    r u using thesis theme? by the way, can u pls tell me which plugin are u using for “spread the word” below your posts? It’s really cool looking;)

    • Jamie July 10, 2010 at 2:25 pm #

      Thanks Britney

      No I’m not using the Thesis Theme but I do like it. “spread the word” isn’t actually a plugin it’s part of my theme.

      • Abeer July 12, 2010 at 6:01 am #


        Hey, how did you implement spread the word in your theme?

        I really liked the idea, would also like to implement something similar on my blog. Please let me know. Thanks :)

  4. Kelly July 10, 2010 at 6:20 am #


    Jamie can you please tell me where the comment loop is and in which file?
    I am a bit new to php and stuff and so just trying get my hands dirty…..

    Thanks so much!

  5. Craig July 10, 2010 at 6:23 am #

    Good work!!

    I don’t understand how people have such great skills in programmming? I always used to get a C in my college programming course. lol ;-)’

    anyways, its good that u have shared it here. my blog’s commenters would become a lot more happy with this feature
    lol ;-)

  6. Lila July 10, 2010 at 6:25 am #

    ya Craig, I agree with you

    the people who comment on my blog will definitely find this interesting and useful since it will show their number of comments

    but dont u think it might discourage commenting if a lot of people just have one or two comments?

    • Trek July 12, 2010 at 6:04 am #

      @Lila, Its like looking at the half filled glass or half empty one… :)

      I believe It might also encourage one or two comment posters to comment more often……..

  7. Steven July 10, 2010 at 6:30 am #

    dude your blog looks all black and white

    Please do not mind but I find it very simple, a web designer should have a blog thats very exciting to view…

    Just my 2 cents

    • Jamie July 13, 2010 at 2:42 pm #

      I appreciate your comments! @steven

  8. Gracie July 10, 2010 at 6:33 am #

    Its good that u explained how to do this

    How about writing a post in which you tell us – What are the benefits of showing number of comments of each comment author??

    • Joy July 12, 2010 at 6:12 am #

      @Gracie, Being a blogger is an exciting job!!

      Al lot of the time you get people suggesting new blog posts to write, so you never run out of material… I have subscribed to your feed. nice site design by the way

  9. Chriss July 10, 2010 at 6:34 am #

    how do I call function inside comment loop?

    Where do I call it? Please tell me, I wanna implement this cool idea for my blog too

    • Samar July 12, 2010 at 6:06 am #

      @Chriss, I am also a newbie Jamie, pls tell me how do I call the function inside the comments loop.

      Thnks in advance

  10. Nitya July 12, 2010 at 6:07 am #

    your site design is so sleek and catchy

    Which theme are u using? Is it a premium one?

    • Raj July 12, 2010 at 6:21 am #

      @Nitya, Hey, even I was wondering the same,This seems to be a rocking theme!!

      and its load time is also very less :)

      Whats the theme, I would like to give it a shot as well dude.

  11. Raj July 12, 2010 at 6:10 am #

    Hey, even I was wondering the same,This seems to be a rocking theme!!

    and its load time is also very less :)

    Whats the theme, I would like to give it a shot as well dude.

  12. Jack July 12, 2010 at 6:13 am #

    Do I need to use a ftp software to make changes in the file or can I do it directly through cpanel?

    • Shweta July 12, 2010 at 6:17 am #

      @Jack, Mate, u can use either of the two methods

      filezilla is a nice program if u wanna do it thru ftp.

      hope that helps :)

      • Jamie July 12, 2010 at 3:06 pm #

        I use Coda by Panic personally.

  13. Sweetie July 12, 2010 at 6:16 am #

    Jamie, I am using thesis theme.

    I do not have functions.php in it. Instead, I can see a file called custom_functions.php

    Where can I put the above code in custom_functions.php file?

    • Jamie July 12, 2010 at 3:05 pm #

      I would recommend the bottom. Just make sure not to intersect any other blocks of code.

  14. Catherine July 12, 2010 at 6:20 am #

    I believe we can also add some cool wordings if we make changes here:

    $oneText = ‘One comment';
    $moreText = ‘% comments';

    for example, changing it to $oneText = ‘starter, 1 comment';

    am I right?

  15. Jimy Adams May 28, 2011 at 4:25 pm #

    Pretty cool post! However, I find that I am already learning more just from the conversations I am having with other attendees.

Leave a Reply