Internet Marketing Idea, Blogging, Tools, Tips, and More…
RSS Feed

Separating WordPress Comments and Pingback/Trackback

Usually we put comments on blog post in the same place with pingback or trackback, this way of placement will create an inconvenient feeling from the readers when we have a lot of comments and pingback/trackback.

Readers will hard to follow and reading comments when we have pingback or trackback in between each comments, this force the readers to made a selection first before able to read the comments in appropriate way.

To separate comments and pingback/trackback in WordPress is easy, we just need to make a little change in our template file.

1st, we need to edit comments.php file, and found this following code, if you use the default theme, this code can be found at line 27. This code is the opening of loop to display all comments that we got.

1
<?php foreach ($comments as $comment) : ?>

2nd, put this new line of code just below the previous code, so its look like this

1
2
<?php foreach ($comments as $comment) : ?>        
   <?php if(get_comment_type() == 'comment') { ?>

3rd, find the code that end the loop

1
<?php endforeach; /* end for each comment */ ?>

4th, add a simple code to close the previous if statement just above the end loop

1
2
   <?php } ?>         
<?php endforeach; /* end for each comment */ ?>

The result will looks like this:

1
2
3
4
5
6
7
8
<h2>Comments</h2>       
<?php foreach ($comments as $comment) : ?>
   <?php if(get_comment_type() == 'comment') {?>
 
   <!-- code to display and format comments .... -->
 
   <?php } ?>
<?php endforeach; /* end for each comment */ ?>

Until here, our post will only show all the comments that we got, and there are no pingback nor trackback on it. More easy to read of course.

But, if you want to display the pingback or trackback too, for example below all the comments, just copy all the code above and change == ‘comment’ into !== ‘comment’ on the if statement, its mean show all comments with comment type is NOT a comment, aka pingback/trackbak, like this:

1
2
3
4
5
6
7
8
<h2>Trackback/Pingback</h2>       
<?php foreach ($comments as $comment) : ?>
   <?php if(get_comment_type() !== 'comment') {?>
 
   <!-- code to display and format trackback/pingback -->
 
   <?php } ?>
<?php endforeach; /* end for each comment */ ?>

Now we have all the comments and pingback/tracback in our blog post, but, in different place. Believe me, its really have the reader to follow the conversations.

Fin.

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

Technorati Tags: ,

Related Posts

Tags: ,

Posted in WordPress



Leave a Reply