• Home
  • Articles
  • Portfolio
  • Contact
Linux/Ubuntu Tutorials
  • Convert AVCHD
  • Convert UIF to ISO
  • Drupal Theming
  • Xbox 360 Media Sharing

How to Highlight Author Comments in Drupal

Posted by Wes on July 08, 2008 | 6 comments

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

on November 26th, 2009 Gerry (not verified) said:

This is just what I need. I no longer have to hire someone to do this in my other site. Thanks mate!

  • reply
on October 2nd, 2009 Zieg (not verified) said:

By moving all search logic to SQL, I was able to add a pager to the search results. This improves usability and performance dramatically.

  • reply
on June 29th, 2009 kaakuu (not verified) said:

This was pointed out to me by VM - http://drupal.org/user/72806
Thanks a LOT to you and VM for this great snippet.

  • reply
on April 7th, 2009 Gavin Doolan (not verified) said:

Thanks this is just what I was after for Drupal 6.

  • reply
on March 25th, 2009 betsson (not verified) said:

yes it really was better. thanks

  • reply
on July 27th, 2008 John (not verified) said:

This is a better solution than what I was using before, and works in D6, too. Thanks.

  • reply

Post new comment

  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This is how I tell if you are human or a bot.
Image CAPTCHA
copy the characters (respecting upper/lower case) from the image.

Search Linux Articles