• Resolved msadventures

    (@msadventures)


    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() ?>
    
    </div>
    
    </div>

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

    Can anyone help?
    Thanks,
    Michelle

    Sorry my post here is a mess, not sure what I’m doing wrong. ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • 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?

    Thread Starter msadventures

    (@msadventures)

    Um, I’m sorry, I don’t speak code very well, I have no idea what your comment means. ??

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    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; ?>

    Thread Starter msadventures

    (@msadventures)

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

    Thread Starter msadventures

    (@msadventures)

    It worked! Thanks! ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Comment number skips first comment?’ is closed to new replies.