Tutorial : Separating Trackbacks From Comments in WordPress 2.7, 2.8 & 2.9
20th Feb 2010 | Posted by Eko S. | 28 CommentsTrackback 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.
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 :
- Thanks to Matt (Sivel.net) for the tutorial.
- and Michael (wpengineer.com) for separate comments and ping count tutorial.
- This tutorial is for wordpress 2.7.x , 2.8.x and 2.9.x for wordpress 2.6.x and older see this tutorial by problogdesign.
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 “<?php the_title(); ?>”</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
but in comments section below, show the total count of your comments without trackbacks/pingbacks : 2 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 “<?php the_title(); ?>”</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 “<?php the_title(); ?>”</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
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 (+)-
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.phpThank you!
/ john
-
Thank you for sharing it. Will you share more about it? I just want to know more.
-
Hmm that’s very interessting but honestly i have a hard time figuring it… wonder how others think about this..
-
Good job…
Thanks for sharing this tutorial.
-
…for Trackbacks and Pingbacks.
-
thanks for info,
amazing and beatifuly -
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.
-
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.
-
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.
-
Hola
Completamente -
Great now I can separating my comment and ping , it’s usefull post .
-
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
-
Thanks for sharing what trackbacks are good for. Very helpful tips. Thanks a lot.
-
Not working for idris theme . Code is completely different to replace ,
-
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.
-
Thanks for that Tutorial.
-
Awesome.. very easy, very usefull.. great tut. Now i just need some styling and im done.. great!
Trackbacks/Pingbacks
- Tutorial : Separating Trackbacks From Comments in Wordpress 2.7 … | Wordpress Marketing
- You are now listed on FAQPAL
- Very Useful 65 Wordpress Hacks | Web Development News
- links for 2010-04-14 « Free Open Source Directory
- Very Useful 65 Wordpress Hacks | Design your way
- Best Way to Display Recent Comments with Gravatar without Plugin
Awesome, now I know what trackbacks are!
Kev