How to Highlight Author Comments in Drupal
Since I switched to drupal 6.x, I have been been looking for way to change the color of an author's comments. Having a distinctive color makes it simple, to quickly scan a thread to see when an author has left a comment. I solved the problem, at first I was using an if statement, to add a class reference, then further refined the code using a ternary operator.
1. First edit comment.tpl.php to add a new class reference (i.e 'author-comment').
This is a snippet of the original comment.tpl.php before the editing:
<div class="comment<?php print ($comment->new) ? ' comment-new' : ''; print ' '. $status; ?>">I used this if statement to add the class reference to the div . It checks if the comment author is the same person as the node's author the comment is attached.
<div class="comment<?php print ($comment->new) ? ' comment-new' : ''; if ($comment->uid== $node->uid): print ' '. ' author-comment'; else: print ' '. $status; endif; ?>">Next I optimized the code by replacing the if statement with a ternary operator.
<div class="comment<?php print ($comment->new) ? ' comment-new' : ''; print ($comment->uid == $node->uid) ? ' author-comment' : ''; print ' '. $status;?>">2. Next you need add this rules to your style.css file.
In this example only the author's comments will be themed with a yellow background and grey outline.
/** Drupal comments **/
.author-comment
{
background-color: #ff5;
border: 1px solid #aaa;
}This method works in drupal 5.x, and drupal 6.x for PHPTemplate-powered themes.

Comments
This is just what I need. I no longer have to hire someone to do this in my other site. Thanks mate!
By moving all search logic to SQL, I was able to add a pager to the search results. This improves usability and performance dramatically.
This was pointed out to me by VM - http://drupal.org/user/72806
Thanks a LOT to you and VM for this great snippet.
Thanks this is just what I was after for Drupal 6.
yes it really was better. thanks
This is a better solution than what I was using before, and works in D6, too. Thanks.
Post new comment