Separating Trackbacks from Comments

Footsteps in the sand. Trackbacks are the messages displayed in the comments list whenever another blog links back to one of your posts. Many blogs disable trackbacks, but not all.

If you use trackbacks on your blog, it is best if they are not mixed with the comments. The comments are a conversation between between real people. Having machine-generated links in the middle of that will only serve to disrupt the conversations.

The method described here will lift out all of the trackbacks, and then display them as a numbered list after the list of comments is finished. Once you have this done, customizing the trackbacks to appear however you want them to is simple.

And thanks to Gary, the Trackbacks header will only appear if the post has a trackback to show.

NB - This method will only work for WordPress users. Sorry guys!

How To Separate the Trackbacks

Open comments.php, and search for the following line:

<?php foreach ($comments as $comment) : ?>

After it, paste the following:

<?php $comment_type = get_comment_type(); ?>
<?php if($comment_type == 'comment') { ?>

Now look for:

<?php endforeach; /* end for each comment */ ?>

And before it, paste:

<?php } else { $trackback = true; } /* End of is_comment statement */ ?>

That means that your list of comments will continue to display as normal, but without any trackbacks or pingbacks. Now we will add a second comments loop for the trackbacks.

Look for the following line:

<?php else : // this is displayed if there are no comments so far ?>

And before it, paste this: (The "Trackbacks" title line can be deleted if you don't want a heading to be shown)


<?php if ($trackback == true) { ?>
<h3>Trackbacks</h3>
<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>
<?php } ?>

Of course, this is all only helpful if you actually use trackbacks, and there are some good reasons for either side of that debate. Do you use trackbacks on your blog? Why?

About the Author - Michael Martin is the founder of Pro Blog Design. He works as a freelance web designer, loves WordPress, and has an unhealthy addiction to smilies. Written on 18th September 2007.

Other posts tagged with , , , , .

Comments

Trackbacks

191 Comments

  1. Hi Michael,

    About time some made a plugin for this (hint hint).

  2. tnx for the original tutorial, much apreciated!

  3. That worked like a charm - thanks for putting that together!

  4. thx for this great tutorial, im gonna test it on my new blog, :)

  5. fascinating and communicative, but would be suffering with something more on this topic?

  6. This tutorial was exactly what I needed.
    These small fixes here and there all around the blog can make such a big difference. This is exactly what I felt about the readability post also man! Wow! simple and thorough!

  7. Thank you - nothing like a good trackback in the middle of a comment *conversation* - nice work.

  8. thanks for this post.I now know what is trackback.

  9. keep up the good work!

  10. I don't know about trackbacks but now i know about trackbacks and there use.Thank you.

  11. i was looking for this
    thank you so much

  12. Thanks for this information rich tutorial.This is an asset for newbie bloggers

  13. I put up my first personal blog yesterday and found this really helpful. Thanks for sharing. Where does everybody get the time?

  14. Ive been looking to separate the two for a while now so thanks for creating a post on this subject.

  15. Very nice information. Thanks.

  16. Hello Michael,

    first of all great explenation and great overall tutorial structure.

    To answere your question, i do use trackbacks because i think it's a nice and very easy way to get to know the people browsing your site, reading your content and actually finding it helpful.

    I do not have many trackbacks on my site but i will definitly change that in future ;)

    Again, great article!

  17. Thank you for putting up this tutorial. Works like a charm in my blog.

    Raymond Selda’s Latest Post: Create A Tabbed Content Rotator Using jQuery

  18. Wow. That worked perfectly! It actually makes the Trackbacks look a lot better on my blog :)

    pchieng’s Latest Post: Lake Miramar Loop 5 Mile Run

  19. I can't find these code for my Thesis theme..
    Another alternative, I must use the plugin.. :p

    baloot’s Latest Post: Reezluz Goes Wild. Jom Baca Post Terpilih Di Blog Reezluv (Info Bisnes, Grafik dan Teknologi)

  20. Sorry, stupid question here:

    Where is the comments.php file found?

    I have found 2 comment.php (no "s") one in the includes and one in the admin, but I can't find comments.php (with the "s")

    Neither of the comment.php files have the text I'm supposed to find.

    Thanks for any help on this basic question!

    Tom

    • Hi Tom,
      It will be in wp-content/themes/your-theme-name . That's the folder that contains all your theme files. If you ever need to edit anything to do with your design, it will be in one of the folders in there! :)

      You never edit the files in wp-admin or wp-includes because your changes would be overwritten when you next upgrade WordPress.

  21. nice! thanks :)

  22. Thanks, I used one of your trackbacks to work out how to put it before the comments :)

    Ben’s Latest Post: Windows Update Won’t Work After Updating to Service Pack 3

  23. Thanks for this, it helps wonders! Now to fix up the CSS.
    Ivy´s last blog ..Beautiful British Columbia

  24. thank you very good ...
    tatil´s last blog ..Çeşme Otel Yeni

Leave a Comment

Not sure how to get an image with your comment?

Link to your latest post? (If possible)