Design Oahu

Web design blog from the middle of the pacific.

WordPress Tutorial: How to put your trackbacks in their own section

On Design Oahu the trackbacks have been separated from the comments. I felt that the trackbacks were a bit of a distraction. WordPress bloggers are most likely used to seeing the trackbacks within the comments section and skip right over them, however I would be willing to bet that new readers get a bit confused when they are trying to read the comments. For the sake of usability and readability I will provide you with some code snippets to move your trackbacks.

You will be editing your comments.php file. The code below is for the default kubrick theme, however the concept will work on your favorite wordpress theme. The additional code you are adding is inserted in the foreach loop, and it is checking to make sure that the comment is truly a comment and not a trackback. The added code is on the second line and the second to last line in the example below.

<?php foreach ($comments as $comment) : ?>
<?php if (get_comment_type() == ‘comment’) : ?>
<li <?php echo $oddcomment; ?>id=”comment-<?php comment_ID() ?>”>
<cite><?php comment_author_link() ?></cite> Says:
<?php if ($comment->comment_approved == ‘0′) : ?>
<em>Your comment is awaiting moderation.</em>
<?php endif; ?>
<br />
<small class=”commentmetadata”><a href=”#comment-<?php comment_ID() ?>” title=”"><?php comment_date(’F jS, Y’) ?> at <?php comment_time() ?></a> <?php edit_comment_link(’edit’,’ ‘,”); ?></small>
<?php comment_text() ?>
/* Changes every other comment to a different class */
$oddcomment = ( empty( $oddcomment ) ) ? ‘class=”alt” ‘ : ”;
<?php endif; ?>
<?php endforeach; /* end for each comment */ ?>

Save your comment.php file at this point. You will see that the trackbacks have been stripped out of the comments. On Design Oahu, the trackbacks are displayed at the very bottom of the page. To do this we just add a simple ordered list. If you are using the default wordpress theme, then you will want to add this snippet just before the very last endif statement.

<?php foreach ($comments as $comment) : ?>
<?php if (get_comment_type() != ‘comment’) : ?>
<li><?php comment_author_link() ?></li>
<?php endif; ?>
<?php endforeach; ?>

This is the basics of what you need to separate your comments and trackbacks. Wordpress makes it very easy, and hopefully in the future this functionality will be added to the core. If you run into any issues feel free to comment on this post and I will do my best to help you out.

If you liked what you read you may be interested in subscribing to our RSS feed or email alerts. You may also want to read up about what RSS feeds are all about.

No comments, go ahead and start it off.

Leave a Comment


  1. WordPress Tutorial: How to style author comments