Aug 12

Displaying pingbacks to your post is a good thing because your readers often will find interesting and value added information in the post that links to your post. What I don’t like is when pingbacks get mixed with the comments to your post, I find that messy. Therefore I decided to separate the pingbacks from my comments and in this post I will show you how I did it.

I guess that some WordPress themes already have this functionality, but mine did not so I decided to implement this by my self.

First I changed the post summary heading to count comments and pingbacks separately. Originally it counted both comments and pingbacks and displayed it as “x comments”. By implementing the following code “x comments and x pingbacks” will be displayed.
Insert the following code in the have_posts() loop in index.php

<div class="post" id="post-<?php the_ID(); ?>">
<div class="date"><span><?php the_time('M') ?>
</span> <?php the_time('d') ?></div>

 <div class="title">
 <h2  class="posttitle">
<a href="<?php the_permalink() ?>" rel="bookmark"
title="Permanent Link to <?php the_title(); ?>">
<?php the_title(); ?></a></h2>

<span id="more-942"></span>

&lt;div class=&quot;postdata&quot;&gt;
&lt;span class=&quot;category&quot;&gt;&lt;?php the_category(', ') ?&gt;&lt;/span&gt;          
&lt;span class=&quot;comments&quot;&gt;
&lt;a href=&quot;&lt;?php the_permalink() ?&gt;#comments&quot;&gt;
&lt;?php fb_comment_type_count( 'comment' ); ?&gt; and 
&lt;?php fb_comment_type_count
( 'pings', 'No Pingbacks', '1 Pingback', '% Pingbacks' ); ?&gt;

This will create the whole header that you see for each post on my blog


Now we need to separate the pingbacks from the comments in the post, I decided to first display all comments then display the pingbacks.
Insert in the comment loop in comments.php

<?php if ( empty($comments_by_type['comment']) ) { ?>
<h3 id="comments">
<?php fb_comment_type_count( 'comment' ); ?>
to &#8220;<?php the_title(); ?>&#8221;</h3>
<ol class="commentlist">
<?php wp_list_comments( 'type=comment' ); ?>
<?php } ?>

<?php if ( empty($comments_by_type['pings']) ) { ?>
<h3 id="comments">
<?php fb_comment_type_count
( 'pings', 'No Pingbacks', '1 Pingback', '% Pingbacks' ); ?>
to &#8220;<?php the_title(); ?>&#8221;</h3>
<ol class="commentlist">
<?php wp_list_comments( 'type=pings' ); ?>
<?php } ?>

By doing so you have successfully separated the pingbacks from your comments


So to achieve this you only need to insert a few lines of code in two .php files :)

I think this is the beauty of WordPress: Very easy to modify just the way you like it. All you need is to know some html and php. If you want to know more about the WordPress php functions you can read about it at Function Reference

Follow me on twitter @PerOla

Share & enjoy
You can subscribe to my comments feed to keep track of new comments.

No Comments to “Separating pingbacks from comments on your (WordPress) blog”

No Pingbacks to “Separating pingbacks from comments on your (WordPress) blog”

Leave a Reply

Subscribe to my comments feed

Subscribe to my feeds Follow me on Twitter