How To Show The Amount Of Comments A Comment Author Made

No Twitter Messages

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.
[php]
function commentCountAuthor(){

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

global $wpdb;

$result = $wpdb->get_var(‘
SELECT
COUNT(comment_ID)
FROM
‘.$wpdb->comments.’
WHERE
comment_author_email = "’.get_comment_author_email().’"’
);

if($result == 1):

echo str_replace(‘%’, $result, $oneText);

elseif($result > 1):

echo str_replace(‘%’, $result, $moreText);

endif;

}
[/php]

Then just call the function inside the comments loop and shazam! Magic!
[php]commentCountAuthor();[/php]

About the Author

JamieI'm a WordPress Designer / Developer, Interstellar Space Geek, WordPress enthusiast and Apple fanboy. When I'm not working I'm genrally hanging out with the family, watching youtube videos and a little gardening.View all posts by Jamie →

  1. PaulPaul07-10-2010

    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

    • JamieJamie07-10-2010

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

      • BobbieBobbie07-12-2010

        @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!! ;-)

        • JamieJamie07-12-2010

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

  2. MichaelMichael07-10-2010

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

    • JamieJamie07-10-2010

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

      • JessicaJessica07-12-2010

        @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. BritneyBritney07-10-2010

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

    • JamieJamie07-10-2010

      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.

      • AbeerAbeer07-12-2010

        @Jamie,

        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. KellyKelly07-10-2010

    Hi,

    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. CraigCraig07-10-2010

    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. LilaLila07-10-2010

    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?

    • TrekTrek07-12-2010

      @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. StevenSteven07-10-2010

    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

    • JamieJamie07-13-2010

      I appreciate your comments! @steven

  8. GracieGracie07-10-2010

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

    • JoyJoy07-12-2010

      @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. ChrissChriss07-10-2010

    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

    • SamarSamar07-12-2010

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

      Thnks in advance

  10. NityaNitya07-12-2010

    your site design is so sleek and catchy

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

    • RajRaj07-12-2010

      @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. RajRaj07-12-2010

    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. JackJack07-12-2010

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

    • ShwetaShweta07-12-2010

      @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 :)

      • JamieJamie07-12-2010

        I use Coda by Panic personally.

  13. SweetieSweetie07-12-2010

    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?

    • JamieJamie07-12-2010

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

  14. CatherineCatherine07-12-2010

    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 AdamsJimy Adams05-28-2011

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