• Resolved BGH_

    (@bgh_)


    Hello people,

    I’m trying to add a number to each comment made on a post, but unfortunately, I just can’t get it right. I don’t want to use a plugin, because it shouldn’t be necessary.

    Here is the code: https://pastebin.com/y1jm1Cm6

    And this is what I have in my comments.php file (only the relevant part):

    <ul class="commentlist">
    				<?php wp_list_comments('callback=custom_comments'); ?>
                </ul>

    Right now, with this setup, it shows the same number in every comment (1, 1, 1…), instead of 1, 2, 3…, for each corresponding comment.

    Could you please help me with this?

    Thanks in advance!

    Best regards.

Viewing 1 replies (of 1 total)
  • Thread Starter BGH_

    (@bgh_)

    Found the solution myself. Just modified the code on the initial post by adding <?php $i = 0; ?> above the wp_list_comments function. And then modified the custom_comments function and added the following:

    function custom_comments($comment, $args, $depth) {
    		global $SMTheme, $i;
    		$i++;

    I was messing around with <?php foreach ($comments as $comment) : ?>, but it is not necessary after WordPress 3+ versions.

    This article enlightened me on the path to solution: https://www.zubair.info/blog/2010/11/13/adding-numbers-to-your-wordpress-comments.html

    Hope this is useful for everyone struggling with this problem!

    Best regards.

Viewing 1 replies (of 1 total)
  • The topic ‘Trying to display each comment number’ is closed to new replies.