Site icon CodeRevolution Knowledge Base

How to: Number your comments – CodeRevolution

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!

Exit mobile version