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!
gotcha! mee trackbacked y00! eh- got a new cell? msg’ed you- no reply. scouting?
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
Good stuff! Thanks for sharing. 🙂