Seperating Trackbacks from Comments
I thought it might be useful to seperate trackbacks from real comments, so set about finding out how to do this. My first search came across a "how to" by problogdesign.com which works well.
However, I wanted the ability to NOT show the "trackback" block of code at all if there is no trackbacks to show. Unfortunately the code supplied in the blog post at problogdesign does not allow for this.
The addition of a simpe "else" and an "if" solves this.
Basically, all you need to do is follow the instructions, but instead of;
-
<?php } /* End of is_comment statement */ ?>
Do this:
-
<?php } else { $trackback = true; } /* End of is_comment statement */ ?>
And instead of this:
-
<h3>Trackbacks</h3>
-
<ol>
-
<?php foreach ($comments as $comment) : ?>
-
<?php $comment_type = get_comment_type(); ?>
-
<?php if($comment_type != 'comment') { ?>
-
<li><?php comment_author_link() ?></li>
-
<?php } ?>
-
<?php endforeach; ?></ol>
Do this:
-
<?php if ($trackback === true) { ?>
-
<h3>Trackbacks</h3>
-
<ol>
-
<?php foreach ($comments as $comment) : ?>
-
<?php $comment_type = get_comment_type(); ?>
-
<?php if($comment_type != 'comment') { ?>
-
<li><?php comment_author_link() ?></li>
-
<?php } ?>
-
<?php endforeach; ?></ol>
-
<?php } ?>
I did try to post this up on the original blog post, but the comments seems to have stripped my code.
You can see this in action at the following post on osWorld, which shows a couple of comments, followed by a couple of trackbacks.

Comment by Michael from Pro Blog Design — October 19, 2007 @ 6:25 pm
Nice post, and thanks for sharing the method.
Comment by SarahG — October 19, 2007 @ 8:22 pm
Definitely looks tidier. Now if only I could work out how to get my trackbacks working again then I'd use this method!
Comment by kristarella — October 20, 2007 @ 4:49 am
Thanks! It worked well.
Comment by burt — October 21, 2007 @ 10:27 am
Yeah, pretty easy change and looks good.
Thanks to Michael for the original code.
Comment by Dave — October 25, 2007 @ 3:42 pm
Thanks to both Michael for the original and Burt for the refinement - the trackbacks look much tidier now.
Comment by Caitlin — November 26, 2007 @ 12:47 am
Thanks for this addition to Michael's original tip! I much prefer trackbacks to be separate from "real" comments. It's easier to read and looks cleaner. ^_^
Comment by Forrest — November 27, 2007 @ 3:48 am
This is a lot more elegant than the java script I came up with to do the same thing…! I think I'll be switching.
Comment by Michael Martin — February 1, 2008 @ 10:02 pm
Hey Gary,
I've updated my original article now to include your improvements, and given you credit of course. Is that okay with you?
Comment by burt — February 2, 2008 @ 10:25 am
Hey Michael - sure no worries. Thanks for the link!
Comment by Michael Martin — February 2, 2008 @ 1:37 pm
Thanks!