Separate Comments From Trackbacks
Author: Stefan Vervoort | Please Comment!To improve the user experience of the comment section of your blog you can do a couple things. You can add Gravatar support to make the comments more appealing, but there is more.
For example, you can separate the real comments from the trackbacks. You often see links or lines of codes mixed up with the original conversation and that can be annoying to the commentator or the people just reading the comments. They might have lost track of the conversation because of the mixture.
Showing Comments Only
The trick to show real comments only is very easy to implant with the use of the comment.php file. The first thing you need to do is open comments.php.
Step 1. Locate the following lines of codes:
<?php foreach ($comments as $comment) : ?>
Figure 1.1
Right after, you need to add a couple lines that filter real comments from trackbacks and pingbacks. The following codes add that functionality:
<?php $comment_type = get_comment_type(); ?> <?php if($comment_type == 'comment') { ?>
Figure 1.2
You need to close this function or your comments.php file will give an error.
Step 2. Locate the following line:
<?php endforeach; /* end for each comment */ ?>
Figure 2.1
Right before that line close the tag:
<?php } ?>
Figure 2.2
It is really important you past that line before the endforeach tag.
Showing The Trackbacks/Pingbacks
As of now, you have real comments left by real people only (if you have a proper spam protection installed), no links will interfere with your conversations.
We aren’t done yet, because we (most likely) want to show appreciation to the blogs that linked to us. We do that by adding trackbacks or pingbacks only too. You have two choices:
- Before the comments
- After the comments
Depending on which spot you choose you have to place the following codes somewhere else.
<h3>Trackbacks</h3> <ol> <?php foreach ($comments as $comment) : ?> <?php $comment_type = get_comment_type(); ?> <?php if($comment_type != 'comment') { ?> <li><?php comment_author_link() ?></li> <?php } ?> <?php endforeach; ?> </ol>
Figure 3.1
Before the comments. If you want to place these codes before the comments, locate the following codes. Remember if you are using a customized theme this might differ a little:
<h2 id="comments"><?php comments_number('No Responses', 'One Response', '% Responses' );?> to “<?php the_title(); ?>”</h2>
Figure 3.2
Add the codes shown in Figure 3.1 right after these codes.
After the comments. If you prefer to put the trackbacks right after the comments (which is in my opinion the best spot to encourage user commenting!) you should locate these codes:
<?php else : // this is displayed if there are no comments so far ?>
Figure 3.3
Add the codes shown in Figure 3.1 right before these codes.










Loading...
8:43 pm on October 3rd, 2008
Can you explain to me how to add the gravatar concept to my site? I started a blog a few months ago and would like to make it more user friendly. I want to make it very similar to a social network, much like MySpace or Facebook. Any ideas on how to do this?
8:53 am on October 4th, 2008
Yes, I have written an article about it;
http://www.divitodesign.com/2008/09/add-gravatar-support-to-wordpress-theme/