One of the greatest disruptions to the conversation that goes on in comments is the trackbacks. They’re great, and I love it when people link to my blog. I always want to separate them because they 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.
We have 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 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+
<?php if (have_comments()) : ?>
<h3 id="comments"><?php comments_number('No Responses', 'One Response', '% Responses');?> to “<?php the_title(); ?>”</h3>
<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 ('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.
<?php endif; ?>
<?php endif; ?>
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 if (have_comments()) : ?>
- Add the following codes after it:
<?php if (! empty($comments_by_type['comment'])) : ?>
- Then find
<?php wp_list_comments(); ?>
- Make it change like this
<?php wp_list_comments('type=comment'); ?>
last step is write this code below after thewp_list_comments
function.</ol><?php endif; ?>
Display pingbacks and trackbacks
You can do it with similar previous step about
<?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 we need to style the pingbacks and trackbacks list by add new functions to functions.php
- Make change
<?php comments_template(); ?>
to<?php comments_template('', true); ?>
insingle.php
- Add new functions to
functions.php
<?php function list_pings($comment, $args, $depth) { $GLOBALS['comment'] = $comment; ?> <li id="comment-<?php comment_ID(); ?>"><?php comment_author_link(); ?> <?php } ?>
You need to call $listping
functions (new style of list pingbacks) in single.php
<ol class="pinglist">
<?php wp_list_comments('type=pings&callback=list_pings'); ?>
Full loop code below
<?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; ?>
This is how we have separated the trackbacks/pingbacks from comments, hidden the trackbacks and styled our comments in WordPress 2.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.