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!

Webdevelopment

6 Responses to My improved Pingbacks/Trackbacks & Comments separation for WordPress 2.0

  1. manuel says:

    gotcha! mee trackbacked y00! eh- got a new cell? msg’ed you- no reply. scouting?

  2. Pingback: blogbox.ch » » Tolle Sache: Kommentar und Trackback getrennt

  3. Will says:

    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

  4. Pingback: Markgrafendamm » Trackbacks vor den Kommentaren

  5. Handy Solo says:

    Good stuff! Thanks for sharing. :-)

  6. Pingback: trellis » Blog Archive » my brain is pouring out

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>