Tutorial : Separating Trackbacks From Comments in WordPress 2.7, 2.8 & 2.9

Trackback is 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.

In layman’s terms, trackback is a way to notify a website when you publish an entry that references it. Trackbacks are the messages displayed in the comments list whenever another blog links back to one of your posts. Pingbacks and trackbacks are great because they mean other bloggers are linking to you, but they can also hurt the conversation within the comments by interfering and cluttering things up.

separate trackbacks

Why separate ?

  • Look professional.
  • Will greatly improve the user experience for the people that comment or read comments on your blog.
  • 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.
  • Looks more organize so your blog commenters have a clearer picture what are the comments, what’s not.
  • Have a clearer picture what are the comments.

How to?

Credits :

Step 1 – Backup

First, make a backup of your comments.php and function.php file just in case something goes wrong

Step 2 – Change singlepage.php

Open file singlepage.php from your theme folder
Look for

<?php comments_template(); ?>

And change with

<?php comments_template('', true); ?>

Step 3 – Hide the trackbacks

Open file comments.php from your theme folder
See comment loop :

<?php if ( have_comments() ) : ?>
       <h3 id="comments"><?php comments_number('No Responses', 'One Response', '% Responses' );?> to &#8220;<?php the_title(); ?>&#8221;</h3>

       <div class="navigation">
            <div class="alignleft"><?php previous_comments_link() ?></div>
            <div class="alignright"><?php next_comments_link() ?></div>
       </div>

       <ol class="commentlist">
       <?php wp_list_comments(); ?>
       </ol>

       <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 ( comments_open() ) : ?>
            <!-- 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; ?>

Find the following code

<?php if ( have_comments() ) : ?>

Directly below this add

<?php if ( ! empty($comments_by_type['comment']) ) : ?>

Look for the following code

<?php wp_list_comments(); ?>

Change with

<?php wp_list_comments('type=comment'); ?>

And directly below wp_list_comments function we modified is

</ol>

Directly this add

<?php endif; ?>

The if statement prevents the comments heading and ol tags from displaying if you only have trackbacks and pingbacks on this post.

Step 4 – Display the trackbacks below the comments

To display trackbacks we need to insert the following code beneath the endif  we just added

<?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; ?>

Now the pings are displayed below the comments.

Step 5 – Display the trackbacks with simple ordered list

The above code will show the pings in full comment boxes. Now we make a simple oredered list with a link and title of the ping (Thanks to Ryan Boren for the tip!)
Open file functions.php on your folder themes and create a callback function for wp_list_comment. Insert the following code

<?php
function list_pings($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;
?>
<li id="comment-<?php comment_ID(); ?>"><?php comment_author_link(); ?>
<?php } ?>

And in file comments.php
Look for

<ol class="commentlist">
<?php wp_list_comments('type=pings'); ?>

And replace with

<ol class="pinglist">
<?php wp_list_comments('type=pings&callback=list_pings'); ?>

Step 6 – Modify the comment counts

Now we will modify the comment counts to only reflect the number of comments minus pings. But if there is no comments and for example have 2 pingbacks, in our blog right under the post title we still have 2 comments displayed.
See this image, we have total 4 comments on this post

4comments

but in comments section below, show the total count of your comments without trackbacks/pingbacks : 2 comments.

separate trackback from comments

Open file comments.php and look for

<?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>

Change with this

<?php if ( have_comments() ) : ?>
<?php if ( ! empty($comments_by_type['comment']) ) : $count = count($comments_by_type['comment']);
($count !== 1) ? $txt = "Comments" : $txt = "Comment";
?>
<h3 id="comments"><?php echo $count . " " . $txt; ?> to &#8220;<?php the_title(); ?>&#8221;</h3>

In this case our full comment “loop” should now look like:

<?php if ( have_comments() ) : ?>
      <?php if ( ! empty($comments_by_type['comment']) ) : $count = count($comments_by_type['comment']);
      ($count !== 1) ? $txt = "Comments" : $txt = "Comment";
      ?>
      <h2 id="comments"><?php echo $count . " " . $txt; ?> to &#8220;<?php the_title(); ?>&#8221;</h2>

      <ol class="commentlist">
      <?php wp_list_comments('type=comment&avatar_size=32'); ?>
      </ol>
      <?php endif; ?>

      <?php if ( ! empty($comments_by_type['pings']) ) : ?>
      <h2 id="pings">Trackbacks/Pingbacks</h2>
      <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; ?>

It’s done :)

Showcase for design inspiration

  1. Hongkiat.com

    hongkiat

  2. Noupe.com

    noupe

  3. DesingM.ag

    designmag

  4. WPHacks.com

    wphacks

  5. DzineBlog.com

    dzineblog

  6. InstantShift.com

    instantshift

Feedback

If you have another method, suggestions or question about this tutorial, please share with us. I hope this tutorial has been useful for you.

Thanks :)

class="commentlist"

22 Comments to “Tutorial : Separating Trackbacks From Comments in WordPress 2.7, 2.8 & 2.9”

Add Comments (+)

  1. Awesome, now I know what trackbacks are!

    Kev

  2. John says:

    This looks like a great tutorial! Too bad my comments.php doesn’t look anything like yours :(
    In my theme comments.php they don’t seem to have used the wp_list_comments function, is that possible? Can’t find it anywhere.
    Where can I get some help as how to separate my comments from pingbacks if I have an odd comments.php

    Thank you!

    / john

    • Eko S. says:

      Hi, John..May I know, you are currently using wordpress version of what? This tutorial only work for wordpress version 2.7.x, 2.8.x and 2.9.x. If your site using wordpress 2.6 and older you can see this tutorial http://www.problogdesign.com/how-to/separating-trackbacks-from-comments/.
      Nice to meet u :)

      • John says:

        No, really, I’m using the latest 2.9.x version. I guess the problem is not wordpress itself but the theme’s “comments.php”
        this is an excerpt from my comments.php file:
        What can be done here?
        ———————————————————————————————–

        to “”

        <li id=”comment-”>
        Says:
        comment_approved == ’0′) : ?>
        Your comment is awaiting moderation.

        <a href="#comment-” title=””> at

        ————————————————————————————————————-

    • Eko S. says:

      Em…your comments.php is unstandart. I’m sorry, I can’t help….I suggest to change your theme with the theme that uses the standard comment loop.
      I previously had difficulty separating trackbacks from the comments, because most of the tutorial using wordpress version 2.6 and earlier. Until finally I found it.

  3. Thank you for sharing it. Will you share more about it? I just want to know more.

  4. Hmm that’s very interessting but honestly i have a hard time figuring it… wonder how others think about this..

  5. Good job…

    Thanks for sharing this tutorial.

  6. Son_Silahsor says:

    …for Trackbacks and Pingbacks.

  7. gunawan says:

    thanks for info,
    amazing and beatifuly

  8. Mark Maranga says:

    What a wonderful and easy tutorial. I’m going to add this to my main weblog. But on one of my blogs I don’t want to REMOVE the Pingback/Trackback option in the Admin, the problem is that the “Comment Count” is not correct. Because it is comment+ping+track. I can’t find any tutorial at the moment. Hopefully you can help.

  9. Kavita says:

    Hi Eko S. Thanks a lot for your wonderful tutorial. This is an important hack all wordpress bloggers require. I have been looking for this hack for many days with changing the code and getting errors resulting in loading of my theme again and again. I am very much relieved today that this code has worked for me.

  10. I still can’t get it to work properly and have the latest version of Word Press!! Frustrating, thanks for the info and tutorial though, probably me.

  11. Garretot says:

    Hola
    Completamente

  12. dimitri says:

    Great now I can separating my comment and ping , it’s usefull post .

  13. Thank you for such a fantastic blog. Where else could anyone get that kind of info written in such a perfect way? I have a presentation that I am presently working on, and I have been on the look out for such information

    Regards

  14. Shaina Tim says:

    Thanks for sharing what trackbacks are good for. Very helpful tips. Thanks a lot.

  15. Ken says:

    Not working for idris theme . Code is completely different to replace ,

  16. Wow! Even if there are a lot of new plug-ins now for WordPress, I guess that this tutorial is still useful as reference and guideline. Honestly, I need this concept now. Thanks.

  17. Thanks for that Tutorial.

  18. Markus says:

    Awesome.. very easy, very usefull.. great tut. Now i just need some styling and im done.. great!

Trackbacks/Pingbacks

  1. Tutorial : Separating Trackbacks From Comments in Wordpress 2.7 … | Wordpress Marketing
  2. You are now listed on FAQPAL
  3. Very Useful 65 Wordpress Hacks | Web Development News
  4. links for 2010-04-14 « Free Open Source Directory
  5. Very Useful 65 Wordpress Hacks | Design your way
  6. Best Way to Display Recent Comments with Gravatar without Plugin

Leave a Reply

 

Amazingly Beautiful WordPress Themes