
You want the comment style to be different for comments added by the author of a node — who's commenting on his own node. For example, you may want to highlight the node's author's comments, so that any visitor skimming through the comments will easily differentiate them from other comments.
Edit comment.tpl.php to add a new class (let's say 'comment-by-author-of-post') that...
you can style in your theme's style.css.
Your file comment.tpl.php may look like this before the edit (I am only providing a snippet of the template here):
<div class="comment<?php print ($comment->new) ? ' comment-new' : ''; print ' '. $status ?> clear-block">If it does, then you will change the above snippet to that:
<div class="comment<?php print ($comment->new) ? ' comment-new' : ''; print ($comment->uid == $node->uid) ? ' comment-by-author-of-post' : ''; print ' '. $status ?> clear-block">You could now add these two rules to your style.css file, for example:
/** * Comment styling rules */ .comment-by-author-of-post { border: 1px solid #ccc; background-color: #eee; } /* reset to default values when previewing */ .preview .comment-by-author-of-post { border: none; background-color: transparent; }
This will work in Drupal 5 as well. No, it won't. The $node object is not passed to the comment.tpl.php template. Read the comments below for the Drupal 5 recipe. This solution works only for PHPTemplate-powered themes. If your theme does not provide a template file for comments, copy the one from modules/comment/ to your theme folder, and edit it. And yes, the $node object is available in comment.tpl.php. It is the node the comment is attached to. Possible variations: special-style all comments authored by those who have the 'admin' role; special-style anonymously-submitted comments; etc.
Comments
Drupal 5?
I am sorry, but this one seems not working with Drupal 5? The snippets from the template for Drupal 5 is supposed to be this one:
And I've changed it to:
But it's still not working. Any help?
Thanks for the attention. :)
In Drupal 5, no $node object in comment.tpl.php
What you do have is the nid of the node the comment is attached to.
So what you need to do is pass the node's author uid, along to comment.tpl.php.
Something like this needs to be done in the file template.php of your theme:
Then you can use $node_uid in comment.tpl.php — that'll be the uid of the node author.
<div class="comment<?php if ($comment->status == COMMENT_NOT_PUBLISHED) print ' comment-unpublished'; print ($comment->new) ? ' comment-new' : ''; print ($comment->uid == $node_uid) ? ' comment-by-author-of-post' : ''; print ' '. $status; ?>">Just one author?
Just one blogger on your web site? Do not bother with checking who is the author of the node. Do not bother with passing an additional variable to your comment template.
In the case where you have only one blogger... you could do as I do here (and yes, my web site still runs on Drupal 5...). Using a hard-coded value for the author of the node, eg: 1 (the Administrator of the site):
<div class="comment<?php print ($comment->uid == 1) ? ' comment-by-author-of-post' : ''; print ($comment->new) ? ' comment-new' : ''; print ($comment->status == COMMENT_NOT_PUBLISHED) ? ' comment-unpublished' : ''; print ' '. $zebra; ?>">Thanks
Sorry for my noobness, but thanks! It works wonderfully on my site. Thanks, once again.
It was my mistake
It was my mistake.
I corrected my 'tutorial', and I am now saying:
Thanks to you!
Thanks for the confirmation
Thanks for the confirmation - had to come back to tell you it didn't work... but of course now it does!
Post new comment