Tutorial – How To Number Your Comments In WordPress
I had the darnedest time trying to figure out how to style my WordPress template to number my comments on a post. Why did I want to number my comments? Having numbers next to a person’s comment would make my job easier when using Random.org in choosing a winner in my giveaways. It makes determining the winner a quick reference as opposed to manually counting.
I read and tried many tutorials. I tried plug-ins. I just could not find anything that seemed to work for me or, in some cases, made sense to me.
Finally, I got comments numbered in my WordPress template. This post was the one post that I found that helped the most. However, I realized most people wouldn’t be able to make sense of it. Also, the post did not mention that the last step had to be put into your blog’s stylesheet.
I decided I’d share what I learned with you in the most simple way I could so that perhaps one of you would not experience the headache that I experienced trying to get my comments numbered in WordPress.
The easiest way I can think to do this is a simple compare & contrast. I took a screenshot of my comments.php file before I changed it as well as after I had added the code that worked. You can find where to edit your comments.php file by selecting Appearance>Editor in your WordPress left sidebar. Then, select “comments.php” in the editor’s right sidebar.
Here is what my comments.php file looked like before I changed the coding (click image to enlarge):
Here is what my comments.php file looked like after I changed the coding (click image to enlarge):
I have highlighted the areas that have changed.
Templates will vary, but below you will find the basic principles. Remember to backup both your comments.php file & your stylesheet file before changing anything. Those backups came in handy for me when I was testing different coding & trying to find one that worked for me.
1. Put the code <?php $i = 0; ?> RIGHT BEFORE the line that says <?php if (?comments) : ?>
2. Put the code <?php $i++; ?> RIGHT AFTER the line that says <?php foreach ($comments as $comment) : ?>
3. Put the code <span class=”count”> <?php echo $i; ?><br /> </span> RIGHT BEFORE the line that says <?php $isByAuthor… or some coding that has “Author” in it.
Now for the part the other post left off.
Open your blog’s stylesheet in your WordPress editor. This is usually called something like stylesheet.css
Put this code:
.authorcomment {
background: #eceef3;
}
.tbcomment {
padding: 5px;
background: url(images/tb.png) no-repeat;
}
.pbcomment {
padding: 5px;
background: url(images/pb.png) no-repeat;
}
somewhere on that page. I put mine at the end of all the comment commands.
Voila! Hopefully, your comments are now numbered in your WordPress template! Good luck!!
If you found this post useful, please hit “I like it” on StumbleUpon or submit this page to your favorite social media community.





















































2 comments
I wish I would have came across this earlier! LOL
Do you use threaded comments? Just curious if it works for them as well. Good for you for figuring it out without using a plugin!
(That is funny that we both started our posts like that! )
Honestly, I have no idea what a “threaded” comment is… lol
Leave a Comment