The last guest post of the week is from David over at ProTycoon.com, with a technical how-to article for WordPress blogs. If you try this out, let us know how it worked!

Brian’s Threaded Comments is a very widely used plugin for WordPress that allows your websites visitors to reply to comments in a threaded fashion. This means that you do not need to address your comment towards people, you can instead just reply to their comment, and the comment is formatted accordingly.

I recently wrote a post for my website which informed my sites visitors how they could amend their comments.php file to separate the comments and trackbacks, thus making the comments section of your blog look alot smarter. As part of Jay’s Guest Blogging period, he thought that it would be a good idea for me to do a follow up to my previous post, but this time teaching how to separate the comments and trackbacks on a blog that is running the ‘Brian’s Threaded Comments‘ Plugin, as this plugin uses a different comments.php file.

The best way to go about making the changes is to have the plugin on your PC and edit the files locally, then upload them. I would also recommend that you make a backup of all files that you edit, just in case something goes wrong.

Once you have the files on your PC you will need to locate the comments.php of the plugin. This is the file that is used to output the comments from the plugin onto your blog.

Once you have the file open you need to locate this section of the code, it is just over half way down:


< ?php if ( $comments ) :
foreach($comments as $c)
{
$GLOBALS['threaded_comments'][$c->comment_parent][] = $c;
}
$GLOBALS['__writeCommentDepth'] = 0;
if( is_array($GLOBALS['threaded_comments'][0]) ) {
foreach($GLOBALS['threaded_comments'][0] as $comment) {
if ( get_comment_type() == "comment" ) {
$GLOBALS['comment'] = &$comment;
write_comment($GLOBALS['comment']);
}
}
}
?>

The above code is used to output the threaded comments.

You need to replace the above code with the following code which filters to find comments and displays them and leaves out the trackbacks, I will give you the code for the trackbacks shortly.

This is the code for filtering out the trackbacks and displays just the comments, put this code in the place of the above code:


< ?php if ( $comments ) :
foreach($comments as $c)
{
$GLOBALS['threaded_comments'][$c->comment_parent][] = $c;
}
$GLOBALS['__writeCommentDepth'] = 0;
foreach($GLOBALS['threaded_comments'][0] as $comment) {
if ( get_comment_type() == "comment" ) {
$GLOBALS['comment'] = &$comment;
write_comment($GLOBALS['comment']);
}
}
?>

You have now separated the comments from the trackbacks, you now need to display the trackbacks, it is advisable that you put the trackbacks underneath the comments, to make things alot smarter. You can do that by adding the following code directly underneath the code you added above:

Responses to this post:

    < ?php foreach ($comments as $comment) : ?>
    < ?php $comment_type = get_comment_type(); ?>
    < ?php if($comment_type != 'comment') { ?>

  • < ?php comment_author_link() ?>
  • < ?php } ?>
    < ?php endforeach; ?>

You may need to edit the format of the above text slightly to fit in with your website. If you do not want your trackbacks to be displayed as a list you can display them as they would normally be seen using the code below instead:

Responses to this post:

    < ?php foreach ($comments as $comment) : ?>
    < ?php $comment_type = get_comment_type(); ?>
    < ?php if($comment_type != 'comment') { ?>
    < ?php write_comment($GLOBALS['comment']); ?>
    < ?php } ?>
    < ?php endforeach; ?>

You should not have the a comments.php file that has the where the ‘#commentlist’ Div tag looks like this:

< ?php if ( $comments ) :
foreach($comments as $c)
{
$GLOBALS['threaded_comments'][$c->comment_parent][] = $c;
}
$GLOBALS['__writeCommentDepth'] = 0;
foreach($GLOBALS['threaded_comments'][0] as $comment) {
if ( get_comment_type() == "comment" ) {
$GLOBALS['comment'] = &$comment;
write_comment($GLOBALS['comment']);
}
}
?>

Responses to this post:

    < ?php foreach ($comments as $comment) : ?>
    < ?php $comment_type = get_comment_type(); ?>
    < ?php if($comment_type != 'comment') { ?>

  • < ?php comment_author_link() ?>
  • < ?php } ?>
    < ?php endforeach; ?>

< ?php else : ?>

< ?php _e('No comments yet.'); ?>

< ?php endif; ?>

You now have a plugin that threads comments and separates the trackbacks. You can now upload the files to your plugins folder, and away you go.

This was a guest post by David Shaw lead author of ProTycoon.com and freelance web designer. David provides great tips on expanding your blog and optimizing it for search engines. If you would like to see more great articles from David Shaw sign up for the ProTycoon RSS
Feeds
.

This blog is supported through sales, not ad clicks. If you like a product I've reviewed, buying it through my link helps keep the site alive and more reviews coming. Also, if you found this post interesting or helpful, consider subscribing to my RSS feed. If you're already a subscriber, thank you!


Rate this:
2.5

Add to Technorati Favorites