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:

a-post-with-an-unordered-list-c2ab-azad-creative_1238605215500

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 entry was posted in Coding, Wordpress and tagged , , . Bookmark the permalink.

3 Responses to How to separate Comments and Trackbacks in WordPress

  1. Pingback: WPscoop

  2. shizterresy says:

    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 . :)

  3. Pingback: You are now listed on FAQPAL

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>