I wanted a little script that would allow me to have specific styles for individual comments depending on the authour.
I had a look around for WordPress plugins and other info, but could not find anything that actually worked.
So I wrote my own little switch statment to sort it all out.
- <?php
- switch (comment_author_email){
- case ($comment->comment_author_email == 'friend@friend.com'):
- $style = '<div class="friendcomment">';
- break;
- case ($comment->comment_author_email == 'you@you.com'):
- $style = '<div class="authorcomment">';
- break;
- default:
- $style = '<div class="defaultcomment">';
- break;}?>
This involves modifying the comments.php file in your theme folder.
Find:
- <cite><?php comment_author_link() ?></cite>
And add this code above that line: Make sure you put the correct email addresses in.
- <?php
- switch (comment_author_email){
- case ($comment->comment_author_email == 'friend@friend.com'):
- $style = '<div class="friendcomment">';
- break;
- case ($comment->comment_author_email == 'you@you.com'):
- $style = '<div class="authorcomment">';
- break;
- default:
- $style = '<div class="defaultcomment">';
- break;}?>
Now find:
- <?php comment_text() ?>
Add the following on the line below:
- </div>
That's it for the comments.php file. Now open your style sheet, usually called style.css and add the following rules to the end of your style sheet, modify to yoru own needs.
- .authorcomment {
- background: #ffffcc;
- padding:10px;
- border:2px solid #000;
- color:#333;
- min-height:90px;
- }
- .friendcomment {
- background: #fff;
- padding:10px;
- border:2px solid #000;
- color:#333;
- min-height:90px;
- }
- .defaultcomment {
- background: #eee;
- padding:10px;
- border:2px solid #000;
- color:#333;
- min-height:90px;
- }
Thats everything. Save and upload your files and see for yourself.
Comment posted by:
DronCourrit
Posted on:
6-12-2007 @ 08:02:36
hey.. very nice


by Soddengecko @ 3:02

The 1 fool before you had this to say about:
“Styling individual comments for WordPress”