How To Add Comment Numbers In Your WordPress Theme ?

There are many WordPress themes that don’t show numbers on comments but we use them because they are better on other sides. So here I am discussing  how to easily add numbers in your WordPress theme’s comments section.

Locate the comments.php file.

Find start of the comment loop. Something like this:

<?php if ( $comments ) : ?>

Add following code immediately above the above given code:

<?php $i = 0; ?>

Find the code that looks like this:

<?php foreach ($comments as $comment) : ?>

Placed following code immediately below the code in the above step:

<?php $i++; ?>

Use following code where you want to display your comment numbers:

<span class=”count”>
<?php echo $i; ?>
</span>

Now click Save.

Open your theme’s stylesheet (style.css) and place following code anywhere on the stylesheet:

.count {
float:right;
padding: 10px;
font-size:18px;
color:#000000;
}

You can adjust CSS to fit your comment numbers in the placement and appearance that you like to have.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.