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:
<?<a title="See also PHP - Transform URL to hyperlinks" href="http://www.whileifblog.com/2010/11/22/php-transform-url-to-hyperlinks/">php</a> if ( $comments ) : ?>
Place this code immediately above the code in Step 3:
<?<a title="See also WordPress - Display AdSense Ads to Search Engines Visitors Only" href="http://www.whileifblog.com/2011/03/21/wordpress-display-adsense-ads-to-search-engines-visitors-only/">php</a> $i = 0; ?>
Now locate the code that looks like this:
<?<a title="See also WordPress - How to Display any External RSS Feed on Your Site" href="http://www.whileifblog.com/2010/12/30/wordpress-how-to-display-any-external-rss-feed-on-your-site/">php</a> foreach ($comments as $comment) : ?>
Placed this code immediately below the code in Step 5:
<?<a title="See also PHP - Magic Constants" href="http://www.whileifblog.com/2012/02/20/php-magic-constants/">php</a> $i++; ?>
Now use this code where you want to display your comment numbers:
<span> <?<a title="See also WordPress - Add Google Analytics" href="http://www.whileifblog.com/2012/03/13/wordpress-add-google-analytics/">php</a> 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.
