One of the greatest disruptions to the conversation that goes on in comments are the trackbacks. They’re great, and I love it when people link to my blog. I always want to separate them because they really detract from the discussions that my readers are having, and they sometimes can make it difficult for a new reader to follow. How about you? This tutorial will show you how to separate Trackbacks/Pings and Comments in WordPress
What is the Difference Between a Comment and a Trackback?
A comment is an interaction between a reader and the blogger about the blog post. A trackback is a link to this post published on another blog post.
The thing it, it’s a little bit different in WordPress 2.7+ than in previous versions, so I had to look up how to split the comments from trackbacks. I started off by making some modifications to the comments.php and functions.php files. Now, comments show up on top, and trackbacks show up below.
The comments loop in WordPress 2.7+
to “”
comment_status) : ?>
As you can see it is much simpler than the old comments “loop”. The majority of everything that is happening is now done via the function wp_list_comments.
To show separate trackbacks and pingbacks on a page in WordPress 2.7 or above, you can change the code in the default comments.php with the following:
Remove pingbacks and trackbacks in comments list
- Open comments.php then find [php]<?php if ( have_comments() ) : ?>[/php]
- Add the following codes after it: [php]<?php if ( ! empty($comments_by_type[‘comment’]) ) : ?>[/php]
- Then find [php]<?php wp_list_comments(); ?>[/php]
- Make it change like this [php]<?php wp_list_comments(‘type=comment’); ?>[/php]last step is write this code below after the wp_list_comments function. [php]</ol><?php endif; ?>[/php]
Display pingbacks and trackbacks
You can do it with similar previous step about
[php]<?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; ?>[/php]
Now we need to style the pingbacks and trackbacks list by add new functions to functions.php
- Make change [php]<?php comments_template(); ?>[/php] to [php]<?php comments_template(”, true); ?>[/php] in single.php
- Add new functions to functions.php[php]<?php
function list_pings($comment, $args, $depth) {
$GLOBALS[‘comment’] = $comment;
?>
<li id=”comment-<?php comment_ID(); ?>”><?php comment_author_link(); ?>
<?php } ?>[/php]
You need to call $listping functions (new style of list pingbacks) in single.php
[php]<ol class=”pinglist”>
<?php wp_list_comments(‘type=pings&callback=list_pings’); ?>[/php]
Full loop code below
[php htmlscript=”true”]
<?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>
<ol class=”commentlist”>
<?php wp_list_comments(‘type=comment’); ?>
</ol>
<?php endif; ?>
<?php if ( ! empty($comments_by_type[‘pings’]) ) : ?>
<h3 id=”pings”>Trackbacks/Pingbacks</h3>
<?php
function list_pings($comment, $args, $depth) {
$GLOBALS[‘comment’] = $comment;
?>
<li id=”comment-<?php comment_ID(); ?>”><?php comment_author_link(); ?>
<?php } ?>
<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; ?>
[/php]
This is how we have separated the trackbacks/pingbacks from comments, hidden the trackbacks and styled our comments in WordPress 2.7.
3 thoughts on “Separate pings from comments in WordPress v2.7+”
I over recall the post is good and on the point. This post indeed helped me in my assignment.
I think this function has to be called in comments.php instead of single.php because I have added mine in comments.php
this paper is accurate to be useful. Thanks to the author.