
Do your blog posts receive lots of comments? If yes, it can be really useful for both you and your readers to number it. Here’s how to do it easily and efficiently.

Do your blog posts receive lots of comments? If yes, it can be really useful for both you and your readers to number it. Here’s how to do it easily and efficiently.
Open comments.php and find the following line:
<?php foreach ($comments as $comment) : ?>
Just above this line, initialize a counter variable:
<?php $i = 0; ?>
Just after this line, increment the counter:
<?php $i++; ?>
Now, you just have to echo the $i variable to get the number of the current comment. Paste this code anywhere on your comments loop:
<?php echo $i; ?>
Your comments are now numbered!
23 Responses
In my opinion, the easiest way to number comments is to use ordered lists, but this is great if you want it to customize the way it looks!
Jean, your code will output always 1.
Put the line $i = 0; above foreach.
@Michael: I said “below” instead of “above” :/ Thanks for letting me know!
This code comes handy if by default the theme isn’t using numbered list. Well, the theme I’m currently using by default has.
I used to number comments that way but now WordPress 2.7 doesn’t use anymore. Whitout this loop numbering the comments is not that easy. Any thoughts on how to implement the numbering in WP 2.7?
Sorry I meant that WP 2.7 doesn’t use the “foreach” anymore
any news about 2.7???
@Daniele @Danny: correct, i have write a solution for 2.7 and all other version of wordpress, easy to use: http://wpengineer.com/numbering-your-comments-pingbacks-trackbacks-or-all/
Thank you Frank, great article!
@Danny: Welcome; best regards.
Haha i have many readers asking me about this. Well I guess its nice to be able to show your comment numbers, if you think they are impressive!
Ben
it doesn’t work on wp2.7.
It’s doesn’t work on WP 2.7
@Jauhari and !CnSoLoer
Frank, 4 comments above, has the solution!
i like this… thanx!!!
Trackbacks: