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.
- First thing you will want to do is create a backup your comments.php file.
- Locate the comments.php file.
- Locate the code that starts the comment loop. It will look something like this:
<?php if ( $comments ) : ?> - Place this code immediately above the code in Step 3:
<?php $i = 0; ?> - Now locate the code that looks like this:
<?php foreach ($comments as $comment) : ?> - Placed this code immediately below the code in Step 5:
<?php $i++; ?> - Now use this code where you want to display your comment numbers:
<span class="count">
<?php echo $i; ?>
</span> - Click Save.
- 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.



Wednesday, October 24th, 2007 at 12:12 pm
Thanks very much, extremely useful!
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!
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?
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.
Sunday, October 28th, 2007 at 2:42 pm
How about just using an ordered list with each comment being a list item?
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!
Monday, July 14th, 2008 at 7:50 am
Works like a charm. Thanks.
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!!!
Thursday, October 9th, 2008 at 10:00 am
Hi, nice script! how can i make the same thing in posts?
thanks in advance
Friday, December 26th, 2008 at 6:31 am
Extremely useful, but novices must have more explanation of using.
Wednesday, January 7th, 2009 at 3:25 pm
Perfect, exactly what I needed. Thank you so much for this tip!
Friday, January 30th, 2009 at 1:27 am
Thank you so much! It’s what I needed!
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.
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?
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
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!
Trackbacks/Pingbacks
Leave A Comment
Become one of our
Featured Sites
Recent Trackbacks
Contributing Authors
Archives
Extras
WordPress Hacks Copyright © 2007-2009 | An Apricot Media Website
Template by StudioPress | Custom Design by Kyle Eslick and Blog Design Studio
RSS Feed Email RSS