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.

Want automatic updates? Subscribe to our RSS feed or
Get Email Updates sent directly to your inbox!
Digg This | Stumble it | Add to Del.icio.us | | Print This

There Are 25 Responses So Far. »

  1. 1 Neil Greenhorn
    Wednesday, October 24th, 2007 at 12:12 pm

    Thanks very much, extremely useful!
    :)

  2. 2 Neil Greenhorn
    Wednesday, October 24th, 2007 at 12:22 pm

    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. 3 Hack WordPress
    Wednesday, October 24th, 2007 at 2:58 pm

    Neil,

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

  4. 4 Neil Greenhorn
    Wednesday, October 24th, 2007 at 3:00 pm

    Sorry :) ,

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

    Everything is sorted,

    Thanks anyway.

  5. 5 Will
    Sunday, October 28th, 2007 at 2:42 pm

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

  6. 6 Kim @ What's That Smell?
    Saturday, June 28th, 2008 at 8:33 pm

    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. 7 Neowster
    Monday, July 14th, 2008 at 7:50 am

    Works like a charm. Thanks.

  8. 8 Christy
    Monday, August 25th, 2008 at 11:28 pm

    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. 9 guasman
    Thursday, October 9th, 2008 at 10:00 am

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

  10. 10 Aerotheme
    Friday, December 26th, 2008 at 6:31 am

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

  11. 11 Kathy Moore
    Wednesday, January 7th, 2009 at 3:25 pm

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

  12. 12 Gaby
    Friday, January 30th, 2009 at 1:27 am

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

    :)

  13. 13 Rick
    Wednesday, March 4th, 2009 at 3:29 am

    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. 14 Derek
    Thursday, March 5th, 2009 at 12:25 am

    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. 15 Sebastien
    Thursday, May 14th, 2009 at 8:30 pm

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

  16. 16 Cindi @ Moomette's Magnificents
    Saturday, June 20th, 2009 at 8:18 pm

    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!



Leave A Comment