WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Display Each Comment Number (14 posts)

  1. cronus3166
    Member
    Posted 6 years ago #

    So I'm working on my comment section, and I have it almost to where I want. But I would like to display next to the author of the comment, the comment number.

    <?php comment_ID();?> would work for most purposes to get what I want across, but if I need to delete a comment, then the numbering gets messed up

    So it could go from 1, 2, 4, 5, 8 (you get the idea)

    Does anyone know the command to keep the count accurate, or a different command to use to display what each comment count is?

    Thanks!

  2. whistler2020
    Member
    Posted 6 years ago #

    my guess is that there is no command. the number probably corresponds to the comment list in the sql database. so you'd need to edit the database directly.

  3. boober
    Member
    Posted 6 years ago #

    in your stylesheet find this

    ol#commentlist {
    list-style:none;
    margin:15px 0 0;
    padding:0;
    }

    and get rid of

    list-style:none;
  4. cronus3166
    Member
    Posted 6 years ago #

    Well I did this, and it works... just not to the degree I was hoping for ^_^

    It shows the number of each comment outside of the div, when I was hoping to have it next to the name of the author and be able to edit it.

    And I know it has to be (somewhat possible), cause I got the idea from the blog.us.playstation.com.

    Although now that I think about it, they may not delete any comments done to their site

    ol#commentlist {
    list-style:none;
    margin:15px 0 0;
    padding:0;
    }

    and get rid of

    list-style:none;

  5. boober
    Member
    Posted 6 years ago #

    well you havent provided a link, so i cant see the issue, but try adding
    list-style-position: inside;

    to get the numbers closer to author name.

    as far as editing them, i have no idea what you mean.

  6. mhsouthpaw
    Member
    Posted 6 years ago #

    The way we did it on the playstation blog is by setting a variable to 1 before the foreach($comments) loop and just echoing and incrementing the variable within the loop.
    Before the loop:

    <?php $cmntCnt = 1; ?>

    Within the loop:

    <?php echo($cmntCnt++); ?>

  7. roodkapje666
    Member
    Posted 5 years ago #

    this works fine mhsoutpaw.
    Thanks!

  8. Dimox
    Member
    Posted 5 years ago #

    Somebody know how to do the same on WordPress 2.7 in threaded comments?

  9. aldolat
    Member
    Posted 5 years ago #

    Like Dimox, I'd like to know how to do the same in wp 2.7.

  10. GregMulhauser
    Member
    Posted 5 years ago #

    Hi folks,

    There's a handy new plugin that provides all kinds of comment numbering options under WordPress 2.7, including hierarchical numbering for threaded comments (e.g., comment number 2 and its replies numbered 2.1, 2.2, 2.3, etc.):

    Greg's Threaded Comment Numbering

    All the best,
    Greg (yep, that 'Greg' -- shamelessly plugin plugging...)

  11. aldolat
    Member
    Posted 5 years ago #

    Hi Greg :)
    I really appreciate your plugin, which works well. The problem is that I would to understand how to number comments in WP 2.7 without using any plugin.

    Thank you for sharing your work! ;)

  12. danielb
    Member
    Posted 5 years ago #

    mhsouthpaw,

    Can I ask a little help on placing the counter? I'm scarely a programmer and it's been about 10 years since I've wrote my last script and it's a bit tricky for me to sort out the Loop..

    I'm trying to use a custom comment display function, here it is:

    function mytheme_comment($comment, $args, $depth) {
    	$GLOBALS['comment'] = $comment; ?>
    	<?php $commentNo = 1; ?>
    	<div class="comment" id="comment-<?php comment_ID() ?>">
    		<div class="commentinfo">
    			<div class="number"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php comment_ID() ?></a></div><div class="author"><a name="<?php comment_ID() ?>"></a><?php printf( get_comment_author_link() ) ?></div>
    			<?php if ($comment->comment_approved == '0') : ?>
    			 Your comment is awaiting moderation.')
    
    			<?php endif; ?>
    			<div class="time"><?php printf(__('%1$s,%2$s'), get_comment_date(), get_comment_time()) ?></div>
    		</div>
    		<div><?php comment_text() ?></div>
    	</div>
    <?php
    }

    And here is the code in comments.php that calls this function:
    <?php wp_list_comments('type=comment&callback=mytheme_comment'); ?>

    If I put the counter declaration inside the function, it's assigned "1" value on every loop, so the counter doesn't work. If I put it outside, it's not seen in the function at all. Please can you tell me what should I do to get this numbering work?

    Thanks

  13. tedcarter
    Member
    Posted 5 years ago #

    I have the same problem of danielb

  14. danielb
    Member
    Posted 5 years ago #

    tedcarter
    I just gave up using the custom function.

    Below is my code. I'm not sure if it's nice but it works :)
    You'll have to add markup appropriate for your theme.

    <?php $i = 0;
    foreach ($comments as $comment) : ?>
    
    	// Prints comment number for approved comments and M-dash for unapproved ones
    	<?php if (($comment->comment_approved == '1')) {  $i++; echo $i; } else { ?>&mdash;<?php } ?>
    
    	// Prints comment info
    	<a name="comment-<?php comment_ID() ?>"></a>
    	<?php comment_author_link(); comment_date('j F Y'); comment_time() ?>
    
    	// Prints comment text for approved comments and notification for unapproved ones.
    	<?php if ($comment->comment_approved == '0') { ?>An administrator must always approve the comment.<?php } comment_text();
    
    endforeach; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic