[resolved] Comment number skips first comment? (6 posts)

  1. msadventures
    Posted 7 years ago #

    Seems like long time, no post...about code issues, anyway.

    I know right off the bat that my problem most likely stems from cobbling together bits and pieces of code, I just don't quite know how to fix it.

    I've started using a theme that didn't include a permalink to each comment, so I'm trying to put in the code to add the permalink and have succeeded...sort of. The comment number, and thus the permalink, always skips the first comment. So for example, if there are three comments, only the last two comments are getting numbered, 1 and 2 respectively. You can see an example of what's going on at this post on my site, which is work safe.

    Here's the code I've used:

    <?php foreach ($comments as $comment) : ?>
    <div id="metacoment">
    <div id="usuario">
    <a href="#comment-<?php comment_ID(); ?>" class="comment_no" title="Permanent Link to this Comment"><?php echo $commentcount++; ?></a>
    <?php comment_type(__('Comment'), __('Trackback'), __('Pingback')); ?> <?php _e('by'); ?> <b><?php comment_author_link() ?></b>
    <p class="tiempo"><?php comment_date('l') ?>, <?php comment_date('F') ?> <?php comment_date('j') ?>, <?php comment_date('Y') ?> at <?php comment_time() ?>

    (I know some is in Spanish, that's how it came with the theme.)

    Can anyone help?

    Sorry my post here is a mess, not sure what I'm doing wrong. :(

  2. Kwebble
    Posted 7 years ago #

    In the code fragment I don't see that $commentcount is being initialized. Perhaps you forgot to set it to 1 before the foreach loop with the comments?

  3. msadventures
    Posted 7 years ago #

    Um, I'm sorry, I don't speak code very well, I have no idea what your comment means. :(

  4. You are doing this:
    <?php echo $commentcount++; ?>

    But you never set $commentcount to 1 to start with in the first place.

    Add this before all that code, just above the foreach line:
    <?php $commentcount = 1; ?>

  5. msadventures
    Posted 7 years ago #

    Ah, thank you! I'm on my way back to work, I'll try that one out tonight. :)

  6. msadventures
    Posted 7 years ago #

    It worked! Thanks! :)

Topic Closed

This topic has been closed to new replies.

About this Topic