How to Separate Pingbacks and Trackbacks from Comments

Categories: Wordpress

According to Wikipedia “A trackback is one of three types of linkbacks, methods for Web authors to request notification when somebody links to one of their documents. This enables authors to keep track of who is linking, and so referring, to their articles”.

separate_coment_trackback2_128

Most bloggers don’t show pingbacks and tracbacks on their blog but if you want to show them then I recommend separating pingbacks and trackbacks from the comments. The main reason I like to separate them is because comments are sometimes an ongoing conversation and trackbacks in the middle kinda breaks the flow of the conversation.

Here is how you can separate the pingbacks and trackbacks from the comments.

search for the following line in your comments.php template file

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

Put the following two lines just after the above line.

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

Now look for the end of the ‘for’ loop so you can close the if statement that you just introduced. To do that search for the following line

endforeach;

Just above that line insert the following code to end the if statement


<?php } ?>

This will filter out the trackbacks and only show comments in this section. If you don’t want to show the pingbacks and trackbacks then you are done. If you do want to show the trackbacks just after the comments section then insert the following piece of code just after the end of for loop section (search for endforeach;)


<?php
/* Loop through comments to count the total pingbacks */
$numPingBacks = 0;
foreach ($comments as $comment) {
if (get_comment_type() != "comment") {
$numPingBacks++;
}
}
?>
<?php if ($numPingBacks != 0) { ?>
<h4>Backlinks/Trackbacks</h4>
<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 } ?>

To see a demo of how this will look like (comments and trackbacks separated) see my WordPress PayPal Shopping Cart plugin post that has quite a large number of trackbacks and comments. I hope this helps.

  • Share/Bookmark
Tags: Web development, web masters, Wordpress

Similar posts that you may like

Subscribe to Tips and Tricks HQ to stay informed

twitter_icon

2 Comments (and 3 trackbacks)

  • #1 by psd graphics on March 15, 2009 - 9:06 pm

    There is no this line

    in default theme, in comments.php

    There is a similar line in comments-popup.php

    Also, there is no “endforeach;” in any of php files in default theme.

    Any help?

  • #2 by admin on March 17, 2009 - 2:54 am

    Sorry, can’t help you with the default wordpress theme as it uses the ‘wp_list_comments’ method to list the comments. You will have to change a fair bit of code in the comments.php to be able to seperate the trackbacks from comments.

CommentLuv Enabled

Featured & Popular Articles

Tips and Tricks Hot Items

wordpress_estore_icon
wordpress membership plugin
WordPress PDF Stamper Plugin
WordPress Affiliate Link Manager Plugin
wordpress_affiliate_plugin_icon