Do you ever feel frustrated to read some trackbacks while you are reading comments of an article? Personally, I hate this. I always want to separate them. How about you? This tutorial will show you how to separate Trackbacks/Pings and Comments in WordPress 2.6 and WordPress 2.7.
WordPress 2.6
1. Open your theme folder, locate the comments.php. Look for
<?php foreach ($comments as $comment) : ?>
2. Add the following codes after it. To start the condition IF it is comment.
<?php $comment_type = get_comment_type(); ?>
<?php if($comment_type == 'comment') { ?>
3. Look for
<?php endforeach; /* end for each comment */ ?>
4. Add the following codes before it. To end the IF condition.
<?php } /* End of is_comment statement */ ?>
To Display Trackbacks/Pings
<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>
WordPress 2.7
The comments.php has a different structure in the new version. Let’s see how it can be done.
1. Open comments.php:
<?php if ( have_comments() ) : ?>
2. Add the following codes after it.
<?php if ( ! empty($comments_by_type['comment']) ) : ?>
3. Look for:
<?php wp_list_comments(); ?>
4. Change to this:
<?php wp_list_comments('type=comment'); ?>
5. We add this codes after the wp_list_comments function.
</ol><?php endif; ?>
To Display Trackbacks/Pings
<?php if ( ! empty($comments_by_type['pings']) ) : ?>
<h3 id="pings">Trackbacks/Pingbacks</h3>
<ol class="commentlist">
<?php wp_list_comments('type=pings'); ?>
</ol>
<?php endif; ?>
The Full Loop
<?php wp_list_comments('type=pings'); ?>
<?php if ( have_comments() ) : ?>
<?php if ( ! empty($comments_by_type['comment']) ) : ?>
<h3 id="comments"><?php comments_number('No Responses', 'One Response', '% Responses' );?> to “<?php the_title(); ?>”</h3>
<ol class="commentlist">
<?php wp_list_comments('type=comment'); ?>
</ol>
<?php endif; ?>
<?php if ( ! empty($comments_by_type['pings']) ) : ?>
<h3 id="pings">Trackbacks/Pingbacks</h3>
<ol class="commentlist">
<?php wp_list_comments('type=pings'); ?>
</ol>
<?php endif; ?>
<div class="navigation">
<div class="alignleft"><?php previous_comments_link() ?></div>
<div class="alignright"><?php next_comments_link() ?></div>
</div>
<?php else : // this is displayed if there are no comments so far ?>
<?php if ('open' == $post->comment_status) : ?>
<!-- If comments are open, but there are no comments. -->
<?php else : // comments are closed ?>
<!-- If comments are closed. -->
<p class="nocomments">Comments are closed.</p>
<?php endif; ?>
<?php endif; ?>
To Simplify the Trackbacks/Pings ( Optional )
1. In single.php. Change this:
<?php comments_template(); ?>
into this:
<?php comments_template('', true); ?>
2. In Comments.php, Add this codes in the trackbacks section. You can also add into your function.php.
<?php
function list_pings($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;
?>
<li id="comment-<?php comment_ID(); ?>"><?php comment_author_link(); ?>
<?php } ?>
3. Look For:
<ol class="commentlist">
<?php wp_list_comments('type=pings'); ?>
4. Replace with this:
<ol class="pinglist">
<?php wp_list_comments('type=pings&callback=list_pings'); ?>
The Full Loop
<?php if ( have_comments() ) : ?>
<?php if ( ! empty($comments_by_type['comment']) ) : ?>
<h3 id="comments"><?php comments_number('No Responses', 'One Response', '% Responses' );?> to “<?php the_title(); ?>”</h3>
<ol class="commentlist">
<?php wp_list_comments('type=comment'); ?>
</ol>
<?php endif; ?>
<?php if ( ! empty($comments_by_type['pings']) ) : ?>
<h3 id="pings">Trackbacks/Pingbacks</h3>
<?php
function list_pings($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;
?>
<li id="comment-<?php comment_ID(); ?>"><?php comment_author_link(); ?>
<?php } ?>
<ol class="pinglist">
<?php wp_list_comments('type=pings&callback=list_pings'); ?>
</ol>
<?php endif; ?>
<div class="navigation">
<div class="alignleft"><?php previous_comments_link() ?></div>
<div class="alignright"><?php next_comments_link() ?></div>
</div>
<?php else : // this is displayed if there are no comments so far ?>
<?php if ('open' == $post->comment_status) : ?>
<!-- If comments are open, but there are no comments. -->
<?php else : // comments are closed ?>
<!-- If comments are closed. -->
<p class="nocomments">Comments are closed.</p>
<?php endif; ?>
<?php endif; ?>
WordPress 2.7 Comment Loop Styling
The new comments loop automatically adds some classes to the LIs tag.
- comment, trackback, pingback classes get added depending on the type of the comment.
- byuser – Added if the comment is by a registered user of the site.
- comment-author-authorname – Added for specific registered users.
- bypostauthor – Added if the comment is by the author of the post the comment is attached to.
- odd and even – Classes are added to odd and even numbered comments
- alt is added to every other comment
- thread-odd, thread-even, and thread-alt – Classes are the same as the odd/even/alt classes, but these only apply to the top level of each set of comments and replies
- depth-1 is added to the top level comments, depth-2 to the next level, and so on.
Theme Upgraded
I’ve upgrade my top selling theme in ThemeForest to support WordPress 2.7 threaded comments. Feel free to check it out. I also have upgraded LoonDesign and Themetation to the latest version. How about you?
Share it!
('
)

This doesn’t seem to work for me.