I’ve noticed a lot of themes that don’t come with numbers on the blog’s comments.  This might not be such a bad thing if you don’t get very many comments, but if your blog does get comments it is probably a good idea to show off how many comments you get by numbering them.

Here are the steps you can take to easily add numbers to your WordPress theme’s comments section.

  1. First thing you will want to do is create a backup your comments.php file.
  2. Locate the comments.php file.
  3. Locate the code that starts the comment loop. It will look something like this:
    <?php if ( $comments ) : ?>
  4. Place this code immediately above the code in Step 3:
    <?php $i = 0; ?>
  5. Now locate the code that looks like this:
    <?php foreach ($comments as $comment) : ?>
  6. Placed this code immediately below the code in Step 5:
    <?php $i++; ?>
  7. Now use this code where you want to display your comment numbers:
    <span class="count">
    <?php echo $i; ?>
    </span>
  8. Click Save.
  9. Now go to your stylesheet (style.css) and place this code anywhere on the stylesheet (probably best placed in the comments section):
    .count {
    float:right;
    padding: 10px;
    font-size:18px;
    color:#000000;
    }

You can adjust the stylesheet to fit your comment numbers into the placement and appearance that you want them to have.

Kyle Eslick is WordPress enthusiast who took his passion for WordPress to the next level in 2007 by launching WPHacks.com as a place to share hacks, tutorials, etc. Connect with Kyle on Twitter or Google+!

  1. Neil Greenhorn says:

    Thanks very much, extremely useful!
    :)

  2. Neil Greenhorn says:

    Really sorry for the double post, but I cannot find or anything like it in my comments.php file,

    Is there another way?

    Thanks!

  3. Hack WordPress says:

    Neil,

    I’m not sure if part of your post didn’t show up. You can’t find anything like which step?

  4. Neil Greenhorn says:

    Sorry :) ,

    Just figured it out, dont know why most of my post was cut off!

    Everything is sorted,

    Thanks anyway.

  5. Will says:

    How about just using an ordered list with each comment being a list item?

  6. Thank you for this straightforward and simple explanation! I spent days with other sites making it so convoluted, your solution took about 30 seconds!

    Thanks again!

  7. Neowster says:

    Works like a charm. Thanks.

  8. Christy says:

    TYVVVVVVVVM!!!!!!

    I have giveaways to start drawing names for tomorrow and with most in the hundreds and one nearing 900, I def did NOT want to count through on each one to find the “right” one as per the random number selector, lol!

    THANK YOU AGAIN!!!

  9. guasman says:

    Hi, nice script! how can i make the same thing in posts?
    thanks in advance

  10. Aerotheme says:

    Extremely useful, but novices must have more explanation of using.

  11. Kathy Moore says:

    Perfect, exactly what I needed. Thank you so much for this tip!

  12. Gaby says:

    Thank you so much! It’s what I needed!
    :)

  13. Rick says:

    Can you suggest how to do it in WP 2.7+ where all the meat of the comment display is done in wp_list_comments()? I have tried using a call back but the variable $i is not available there so I can’t increment nor display it.

    Even using OL (as demonstrated in the default theme) is no good when the comments are paged because every new page STARTS FROM 1 making it useless. Goodness knows what happens with threaded comments, I haven’t tried yet.

  14. Derek says:

    My comments are currently setup to show the newest comments on top, instead of the default oldest first.

    Using this tutorial, it’s labeling my latest comment as #1,2,3 etc…

    So say I have 15 comments, it is showing my 15th comment as #1.

    Any easy way to reverse this order?

  15. Sebastien says:

    Yeah! Thanks a lot. I’ve looked around for a solution to comment numbering for like 30 minutes! Clear and simple! Thanks again

  16. Thanks so much for this easy to follow explanation! I would have been looking for a plugin forever!

    It was so easy that even this Baby Boomer did it!

  17. Kimberly says:

    Thanks so much! Super easy to follow and worked perfectly!

  18. shmolik katz says:

    doesnt work for me.
    where should u put no. 7 ?
    isnt there a plugin that can do that for low tech people, other then me ….

  19. Rajee says:

    Hi,

    My theme doesn’t have this code

    Sorry for the first comment.

    Please help.

  20. matt says:

    thank you, i have a problem. somehow my comments-count does work blog-wide?? not only the comments of each post get counted from 1 to whatever, but the comments of all posts get counted! so it could be that i have a 10 posts on my blog, every post has a few comments, so the tenth post starts with comment number 35??? what i’m doing wrong?

  21. Could you update this for the newer versions of WordPress? I’m using 2.8.4. The code in comments.php is totally different and it’s hard to figure out where to put what. Thank You!

  22. Justin says:

    — *** SOLUTION *** —

    If you’re looking for a way to do that in WP 2.8.X, here’s how to:

    Go in your comment-template.php file in the wp-includes folder, and go to the “get_comments_number” function (approx. line 520).

    After “global $id;” (always in the “get_comments_number” function), add ” global $count; “.

    That’s it! Now all you have to do, in your index.php file (or whatever), add

    I’d recommand changing, in the “get_comments_number” function, the variable “$count ” to something else so a plugin doesn’t “interfere” with this global variable in the future. Per example, in my case, I renamed it to “$countcomments”. So it gives me this:

    function get_comments_number( $post_id = 0 ) {
    global $id;
    global $countcomments; /* First modification */
    $post_id = (int) $post_id;

    if ( !$post_id )
    $post_id = (int) $id;

    $post = get_post($post_id);
    if ( ! isset($post->comment_count) )
    $countcomments = 0; /* Second modification */
    else
    $countcomments = $post->comment_count; /* Third modification */

    return apply_filters(‘get_comments_number’, $countcomments); /* Fourth modification */
    }

    Now in my index.php, I just putted .

    Good luck!

    • Jay says:

      Thanks Justin, but look like some words are missing in your comment oO. What do we have to add in the index.php file ? Thanks

    • charlie says:

      Your code for what to put in the index.php has been cut off. Can someone please edit so that we know how to show the number of the comment??? No use if the code isn’t there.

    • Janet says:

      Hi Justin

      Thanks for your post. I’m just getting started blogging but know I want a comment counter. So far per your instructions, I’ve amended the comments-template.php file according to your example (which if I am correct removes the $post id before the /*Fourth notification, right?).

      Anyway, as per a few other commenters, you seem to have left out some vital info re the index.php page and what to add in there? And do I need still need to amend the css stylesheet also?

      Could you pm me as your help would be greatly appreciated.
      Many thanks
      Janet

      • Justin says:

        Just to let you know: I didn’t left anything out. I put everything that was needed, but WordPress cut off a large portion of the code since I didn’t put it in a “code” tag (didn’t know at the time). I thought the author of this article would take a few seconds to look at it and complete it since this isn’t that difficult, but I guess not.

        I’ll do a complete tutorial on my Blog pretty soon and post the link here.

  23. Sophie says:

    Thanks for the solution Justin

  24. Thank you for these very easy instructions!

  25. This rocked! It was so easy! It actually worked right the first time! Many, many thanks!

  26. Elizabeth @ MomCooks says:

    My theme doesn’t have . I’m using a WP 2.9.2 compatible theme. Any suggestions?

  27. Matias says:

    awesome, it was very helpful :)

  28. Joy says:

    That’s great! thank you for the tip

  29. Joy says:

    That’s really a useful hack, appreciate

  30. Thanks for the solution Justin

  31. 13770 says:

    I have is the same as Derk (http://wphacks.com/how-to-adding-comment-numbers-to-your-wordpress-theme/#comment-6253) my comments are currently setup to show the newest comments on top, instead of the default oldest first. How can I change the order, number 1 at the bottom and the most recent at the top.
    Thnak you

  32. durian says:

    is this script still working for wp 3.2? update please!!

  33. BJ says:

    Update the script this is old..

    Nobody use this WP version anymore..

  34. Newman says:

    My solution for WP 3.2… I used the “Twenty Ten 1.0″ functions.php for example… in function twentyten_comment() (note: this function is called back from comments.php by wp_list_comments() to get template for comments and pingbacks). I just add a global variable ($GLOBALS['mycommentnumber']) and after that just increment by one:

    1st step: comments.php

    ‘twentyten_comment’ ) ); ?>

    _____________________________________________________
    2nd step: functions.php
    function twentyten_comment( $comment, $args, $depth ) {
    $GLOBALS['comment'] = $comment;
    switch ( $comment->comment_type ) :
    case ” :
    $GLOBALS['mycommentnumber']++; // first change ?>
    <li id=”li-comment-”>

    <div id="comment-” class=”comment-box” >

    not so complicated right? jajajajajajajajaja… that was useful for me, so I share it…

    • Newman says:

      Wrote again…
      1st step: comments.php

      'twentyten_comment' ) ); ?>

      2nd step: functions.php

      function twentyten_comment( $comment, $args, $depth ) {
      $GLOBALS['comment'] = $comment;
      switch ( $comment->comment_type ) :
      case '' :
      $GLOBALS['mycommentnumber']++; // increment value by one ?>
      <li id="li-comment-">

      <div id="comment-" class="comment-box" >

  35. Wine Dine says:

    Thanks for the code snippets and steps.

Trackbacks/Pingbacks »

  1. Wordpress Hacks, Guides and Tricks | TechnoBuzz.net says:
  2. WordPress ?? ??? ??? tutorial says:
  3. Top 30 Most Wanted Wordpress Tricks and Hacks | Make Money Blogging Experiment says:
  4. Geek Week - This week jQuery tutorials, CSS3, & WordPress - PHP, XHTML, Web Design, Flash | JasonCypret.com says:
  5. Wordpress Updates » Blog Archive » Adding Comment Numbers to Posts says:
  6. 50+ Different Ways To Vastly Improve Your Wordpress Blog | Web Media Magazine says:
  7. How to Speed Up Your WordPress Blog by Having Less Plugins | WebTechWise says:

Tweetbacks »

  1. veza (Vesa) says:
  2. CoutureNerd (CoutureNerd) says: