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.















Thanks very much, extremely useful!
Really sorry for the double post, but I cannot find or anything like it in my comments.php file,
Is there another way?
Thanks!
Neil,
I’m not sure if part of your post didn’t show up. You can’t find anything like which step?
Sorry
,
Just figured it out, dont know why most of my post was cut off!
Everything is sorted,
Thanks anyway.
How about just using an ordered list with each comment being a list item?
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!
Works like a charm. Thanks.
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!!!
Hi, nice script! how can i make the same thing in posts?
thanks in advance
Extremely useful, but novices must have more explanation of using.
Perfect, exactly what I needed. Thank you so much for this tip!
Thank you so much! It’s what I needed!
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.
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?
Yeah! Thanks a lot. I’ve looked around for a solution to comment numbering for like 30 minutes! Clear and simple! Thanks again
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!
Thanks so much! Super easy to follow and worked perfectly!
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 ….
Hi,
My theme doesn’t have this code
Sorry for the first comment.
Please help.
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?
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!
— *** 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!
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
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.
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
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.
Many thanks. I look forward to checking that out.
Kind regards
Janet
Thanks for the solution Justin
Thank you for these very easy instructions!
This rocked! It was so easy! It actually worked right the first time! Many, many thanks!
My theme doesn’t have . I’m using a WP 2.9.2 compatible theme. Any suggestions?
awesome, it was very helpful