• Resolved cronus3166

    (@cronus3166)


    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!

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

    in your stylesheet find this

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

    and get rid of

    list-style:none;

    Thread Starter cronus3166

    (@cronus3166)

    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;

    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.

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

    this works fine mhsoutpaw.
    Thanks!

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

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

    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…)

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

    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

    I have the same problem of danielb

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

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Display Each Comment Number’ is closed to new replies.