Support » Fixing WordPress » Comments question

  • Hi there,

    I’ve written a simple function in my functions.php to display the list of comments slightly differently than the default wp_list_comments() output. So my function code looks like this:

    function theme_comments ($comment, $args, $depth) {
       $GLOBALS['comment'] = $comment; ?>
       <li <?php comment_class(); ?> id="comment-<?php comment_ID() ?>">
             <?php echo get_avatar(get_comment_author_email(), 40); ?>
          	<?php comment_text() ?>
          	<p class="comment-author">Posted on <?php printf(__('%1$s'), get_comment_date()); ?><br />by
          	<strong><?php printf(__('%s'), get_comment_author_link()) ?></strong><?php edit_comment_link(__('(Edit)'),'  ','') ?>
            <?php if ($comment->comment_approved == '0') : ?><br /><strong><?php _e('Your comment is awaiting moderation.') ?></strong><?php endif; ?>
            <hr />
    <?php } ?>

    Now this works fine, but I would like to fine tune this a little. Notice the hr tag at the end of the code. I would really prefer if that horizontal rule would not display for the last comment for the post. For example if there is only one comment, there is no need to have that divider line between comments.

    Any suggestions are greatly appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Why not wrap it in a conditional based on the comment count? If the comment count is greater than 1, display the horizontal rule, otherwise don’t?

    You could also set a var as a counter and when the var is equal to the total number of comments (as you’re looping through) then don’t display it. That should happen on your last comment.

    I don’t want the horizontal rule to display on the last comment, no matter how many comments there are so the first idea won’t work.

    However, I agree with your second idea that if a variable is setup to count the number of comments and if the total number of comments is equal to the comment number then the horizontal rule is not displayed.

    Sounds great, but I’m not sure how to write that code…

    I have done extensive research on comment counting or numbering comments, and I fail to see any solution that works for the latest version of wordpress (3.0.4)

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Comments question’ is closed to new replies.