How to separate Comments and Trackbacks in Wordpress
Comments, Trackback and Pingbacks are mixed up and shown together by default in Wordpress. For presentational purposes, you want to separate them and list them separately. Here’s a simple trick that shows how to.
Why you might want to separate comments and trackbacks:
- Makes the comment list look a lot more neat
- Trackbacks interrupt on the flow of conversation in the comments
- Trackbacks are basically link-juice for both sides, which you may want to show below the comments
What makes the comments and trackbacks show up together is this line in comments.php:
[/sourcecode] Luckily, Wordpress offers termendous flexibility to manipulate the template and basically lets you do almost anything imaginable. By simply adding a parameter, we can filter the comments. The following returns only comments: [sourcecode language="php"]
We can further manipulate the presentation of the comments. By adding a callback function, we can now change the way comments are displayed. So this is what it looks like:
[/sourcecode]
The function <em>ac_comment</em> is called from functions.php. So add the following lines to your functions:
[sourcecode language="php"]function ac_comment($comment, $args, $depth) {
$GLOBALS['comment'] = $comment; ?>
<div class="<?php if ($comment->comment_author_email ==">" id="comment-">
<div class="commentHeader">
<div class="gravatar">
' ); ?>
</div>
<div class="commentMeta">
<div class="commentAuthor">
</div>
<div class="replyDate">
<a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"></a>
</div>
</div>
</div>
<div class="commentBody">
comment_approved == '0') : ?>
<em></em>
</div>
</div>
As you can see, you can do pretty much anything you want to it. Off course, replace you@yourdomain.com with your admin email address so that author comments get a unique classname which can be styled with CSS. Here’s an example of what it should looks like in my theme:

On the other hand, the Trackbacks and Pingbacks can be called with this function:
[/sourcecode]
It uses the parameter pings as type and calls on the ac_pings callback function.
Here is the code in functions.php
[sourcecode language="php"]function ac_pings($comment, $args, $depth) {
$GLOBALS['comment'] = $comment; ?>
<div id="ping-<?php comment_ID(); ?>" class="ping">
</div>
That should separate the comments and trackbacks quite neatly, giving you complete flexibility over the presentation. I will leave it to you style them with your own CSS.
This website is hosted by DreamHost. Get $25 Off with promo code: AZADCREATIVE

















Comments
(3) Skip to comment formshizterresy
June 3, 2009 at 7:26 pm
Sweet blog. I never know what I am going to come across next. I think you should do more posting as you have some pretty intelligent stuff to say.
I’ll be watching you .
WPscoop
April 2, 2009 at 8:16 am
WPscoop…
Your story was featured in WPscoop! http://wpscoop.com/Wordpress-Tutorials/How-to-separate-Comments-and-Trackbacks-in-Wordpress-2-7...
You are now listed on FAQPAL
July 26, 2009 at 6:34 pm
How to separate Comments and Trackbacks in Wordpress…
How to separate real comments and trackback pingbacks in Wordpress blog…