• After goiong through many posts here, I have finally modified my theme to insert a comment number instead of order list. However I need another advise on how to sort the comment number in decending order.

    Please advise. Thanks in advance.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter akira01

    (@akira01)

    Any help would be appreciated

    Simplest method: Building from this, we can decrement the value for each comment. So *before* the comments loop starts, that is outside of it, place this in your comments template:

    <?php $comment_num = get_comments_number(); ?>

    Then in the comments loop:

    <?php echo $comment_num; $comment_num--; ?>

    The $comment_num--; piece is key here, as it will decrement the value of $comment_num for the next iteration of the loop.

    EDIT: Wanted to note this can also be used with an ordered HTML list:

    <li value="<?php echo $comment_num; $comment_num--; ?>">

    Thread Starter akira01

    (@akira01)

    thanks, I will test it out now.

    Thanks again

    Thread Starter akira01

    (@akira01)

    I am using the following code to create a comment number :

    <?php $i = 0; ?>
    <?php if ( $comments ) : ?>


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

    and add the following code in where I want the number to appears:

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

    Where should I put your code? Please advise. Thanks

    You can change:

    <?php $i = 0; ?>

    to:

    <?php $i = get_comments_number(); ?>

    (Though $i is a bit generic…) Remove:

    <?php $i++; ?>

    And change:

    <?php echo $i; ?>

    to:

    <?php echo $i; $i--; ?>

    Thread Starter akira01

    (@akira01)

    Thanks. It works.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘how to sort comment number in decending order’ is closed to new replies.