Display comments and trackbacks separately

October 19, 2008 · Print This Article

When you’re reading comments on a blog post, trackbacks are annoying. It’s way better to display it separately from comments.

Open and edit the comments.php file from your theme. Find the comment loop:

foreach ($comments as $comment) : ?>
// Comments are displayed here
endforeach;

Replace it with the following:
<ul class="commentlist">
<?php //Displays comments only
foreach ($comments as $comment) : ?>
<?php $comment_type = get_comment_type(); ?>
<?php if($comment_type == 'comment') { ?>
<li>//Comment code goes here</li>
<?php }
endforeach;
</ul>

<ul>
<?php //Displays trackbacks only
foreach ($comments as $comment) : ?>
<?php $comment_type = get_comment_type(); ?>
<?php if($comment_type != 'comment') { ?>
<li><?php comment_author_link() ?></li>
<?php }
endforeach;
</ul>

As you probably noticied, we used the get_comment_type() hook, which return a string containing the comment type.


Your choice for site templates and wordpress themes

Comments

Got something to say?

You must be logged in to post a comment.