My improved Pingbacks/Trackbacks & Comments separation for WordPress 2.0

Rachel Runcliffe posted a topic on separating Pingbaks/Trackbacks from Comments in WordPress 2.0 … now, I’ve improved this thingy by implementing a third loop which first counts the number of Pingbacks/Trackbacks & Comments so that the HTML still remains valid. Anywho, here goes

Procedure to install this still remains the same: edit the comments template of your current wp-theme. Copy the piece of code below and paste it over the current comments loop…

<?php if ($comments) : ?>

<?php /* Count the totals */
$numPingBacks = 0;
$numComments  = 0;

foreach ($comments as $comment) {
if (get_comment_type() != "comment") {
$numPingBacks++;
} else {
$numComments++;
}
}
?>

<?php if ($numPingBacks != 0) : ?>
<h3 id="trackbacks">Trackbacks/Pings</h3>
<ol class="commentlist">
<?php foreach ($comments as $comment) : ?>
<?php if (get_comment_type() != "comment"){ ?>
<li class="<?php echo $oddcomment; ?>" id="comment-<?php comment_ID() ?>">
<cite>
<span class="author"><?php comment_author_link() ?></span>
<span class="date"><?php comment_date('M d Y') ?> / <?php comment_date('ga') ?></span>
</cite>

<div class="content">
<?php if ($comment->comment_approved == '0') : ?>
<em>Your comment is awaiting moderation.</em>
<?php endif; ?>
<?php comment_text() ?>
</div>
<div class="clear"></div>
</li>
<?php /* Changes every other comment to a different class */
if ('alt' == $oddcomment) $oddcomment = '';
else $oddcomment = 'alt';
?>
<?php } ?>
<?php endforeach; /* end for each comment */ ?>
</ol>
<?php endif; ?>

<?php if ($numComments != 0) : ?>
<h3 id="comments">Comments</h3>
<ol class="commentlist">
<?php foreach ($comments as $comment) : ?>
<?php if (get_comment_type() == "comment"){ ?>
<li class="<?php echo $oddcomment; ?>" id="comment-<?php comment_ID() ?>">
<cite>
<span class="author"><?php comment_author_link() ?></span>
<span class="date"><?php comment_date('M d Y') ?> / <?php comment_date('ga') ?></span>
</cite>

<div class="content">
<?php if ($comment->comment_approved == '0') : ?>
<em>Your comment is awaiting moderation.</em>
<?php endif; ?>
<?php comment_text() ?>
</div>
<div class="clear"></div>
</li>
<?php /* Changes every other comment to a different class */
if ('alt' == $oddcomment) $oddcomment = '';
else $oddcomment = 'alt';
?>
<?php } ?>
<?php endforeach; /* end for each comment */ ?>
</ol>
<?php endif; ?>
<?php else : // this is displayed if there are no comments so far ?>

Happy copy-n-pasting!

Join the Conversation

6 Comments

  1. Hey,

    Nice fix! 🙂

    Just one little problem with this bad boy, it shows pings/trackbacks as comments on the home page. That is it shows for example, “three are 3 comments” . When in fact there is 1 trackback and two comments. 🙁

    Any idea on how to fix?

    Thanks,

    Will

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.