Unique Author Comment Styles in Wordpress

When I first looked into making styled author comments, I got a bit of a headache sifting through all of articles out there. There weren’t many that solved the problem from start to finish. The most helpful introduction I found was on the Aonach Consulting blog.
The above post will be the starting point for today’s tutorial. We’ll use some PHP and Wordpress magic to sort through and style a variety of comments based on the role of the author.
The Goal
By the end of this tutorial, we’ll have set up a comment system which automatically highlights comments according to the commenter’s role. For our example, we’re going to aim for an end result similar to the screenshot below. Comments will be highlighted based on roles of guest, author, and blog administrator.
The live demo below is meant to illustrate the end HTML and CSS result, and is not running on Wordpress.

Sort Through Each Comment
In your Wordpress theme folder, open up the file “comments.php” for editing. This is the Wordpress file responsible for compiling and displaying all of the comments for a given post. All of the code in this section will be inserted into this file.
To get situated, locate the following line of your comments.php file:
<?php foreach ($comments as $comment) : ?>
This is the start of the commenting loop. We’ll be writing all of our (non-CSS) code inside of it, because each comment will need to be individually checked. The PHP loop below will do just that. It will check each comment, and determine whether or not it was made by the author based on the email used to post/comment.
This loop will also determine which comments are made by blog owners specified by email. In this case, there are two blog administrator emails (guest2@testdemo.com and guest@testdemo.com).
Just below the start of the commenting loop, copy in this block of PHP:
<!--Check if comment is by the author-->
<?php
$isByAuthor = false;
$isByAdmin = false;
if($comment->comment_author_email == get_the_author_email()) {
$isByAuthor = true;
}elseif($comment->comment_author_email == "guest2@testdemo.com" || $comment->comment_author_email == "guest@testdemo.com"){
$isByAdmin = true;
};
?>After we’ve determined the nature of the comment, we’ll create the comment from the results. You should already have the list item tag for each comment structure in place, so you’ll want to edit it to match the below example. The most notable change is the PHP conditional statement which assigns a different class to each list item depending on whether or not it is made by an author or administrator.
<li class="<?php if($isByAuthor) { echo 'author-comment';}elseif($isByAdmin){ echo 'admin-comment'; }?>" id="comment-<?php comment_ID() ?>">
<div class="comment-padding">
<div class="gravatar-col">
<?php echo get_avatar( $comment, 64 ); ?>
</div>
<div class="comment-col">
<cite><?php comment_author_link() ?></cite>
<?php if ($comment->comment_approved == '0') : ?>
<p><em>Your comment is awaiting moderation. Sit tight!</em></p>
<?php endif; ?>
<p class="datestamp"><a href="#comment-<?php comment_ID() ?>" title=""><?php comment_date('F jS, Y') ?> at <?php comment_time() ?></a></p>
<?php comment_text() ?>
</div><!--End of comment column-->
</div>
</li>At this point, you’ll end up with all of your comments shown as usual but with class names (e.g. authorcomment) that represent their type.
Base Comment Styles
Before we change the styles for special comments, let’s take a look at the CSS for a normal comment. Essentially what we’ll be doing is setting default styles for each comment, and then using specific class names to overwrite the relevant ones as needed.
/*Comment Styles*/
ol#comment-zone{padding:12px;}
/*Default comment (Guest)*/
#comment-zone li{list-style:none; margin:12px; padding:15px; clear:both; height:74px; background:#F7F7F7; border: 1px solid #DFDFDF; font-family:Georgia, "Times New Roman", Times, serif; font-size:12px;}
#comment-zone li a{color:#0B5780;}
#comment-zone li cite {font-style:normal; font-size:14px; font-weight:bold;}
#comment-zone li cite a{text-decoration:none;}
#comment-zone li img {border:5px solid #CFCFCF; width:64px; height:64px;}
#comment-zone li .gravatar-col{clear:left;float:left; min-height:100px; width:90px;}
#comment-zone li .comment-col{float:left;padding-right:30px; min-height:100px; width:420px;}Style the Author Comment
This is your kingdom; speak with authority. Use a color that will stand out and grab attention.

The CSS below will overwrite the base styles to achieve the unique look above.
/*Author Comments Styles*/
#comment-zone li.author-comment{background:#1F1F1F; color:#F7F7F7; border:1px solid #474747;}
#comment-zone li.author-comment img {border:5px solid #474747;}
#comment-zone li.author-comment a{color:#b6d7e9;}Handling Multiple Owners
We could apply this idea to blogs run by multiple authors. Take Build Internet! for example. Let’s say Sam wanted to make a comment on this post. Even though he was not the author, I would still like for him to stick out from the rest even though he did not write it.
Ideally, the author would have the largest visual hierarchy, then blog admins, followed by guest comments. In this example, there is only a slight difference of shading involved between administrator and author comments. The CSS is essentially the same between author and administrator comments:
/*Admin Comment Styles*/
#comment-zone li.admin-comment{background:#333; color:#F7F7F7; border:1px solid #474747;}
#comment-zone li.admin-comment img {border:5px solid #474747;}
#comment-zone li.admin-comment a{color:#b6d7e9;}Alternatively you could take the route of assigning each authors their own unique highlight color. You would simply just have to assign more possibilities to the initial identifying loop.
Stand Out More
With the concepts of this tutorial there is no limit to the amount of customization possible in comment styles. A dedicated designer might even style based on things like nationality (via IP address) or any number of other identifiers. Think about it, and if you come up with any fresh ideas please share in the comments below.
To make life easier, I’ve included both a sample comments.php file and the html/css version in the source files. The two of them should help to get your own comment highlighting rolling, especially if you’ve gotten a little lost from different theme structures. If you have any leftover issues, let us know and we’ll see if we can set you straight!














Discussion
April 26th, 2009 at 9:37 PM
Hey!
Really nice post, i was looking for that for some time already.
April 27th, 2009 at 1:37 AM
this is really good tutorial. really useful for multi-author blog. thanks.
izzat aziz’s last blog post..20 Comment Design For Inspiration
April 27th, 2009 at 1:49 AM
really helpful, thanks for that!
Marvin’s last blog post..Ein Herz für Blogs
April 27th, 2009 at 9:30 AM
Thanks! I think this is one of the often neglected areas of design – quite helpful of you to provide this tutorial!
April 27th, 2009 at 4:50 PM
Nice tutorial Zach! I’ll be implementing this on MyInkBlog soon
Andrew Houle’s last blog post..10 Awesome Free Serif Fonts
April 27th, 2009 at 8:12 PM
nice tutorial. I have this method in my site. Slightly different way. Thanks for sharing
Kawsar Ali’s last blog post..40 Logo Design Tutorials
April 28th, 2009 at 2:49 AM
How can you do the same thing with threaded comments in WP 2.7?
April 28th, 2009 at 5:46 AM
Great post! I was searching for something like that for a while. Wonder how it will work out on my blog. Thanx
Roland Kopp-Wichmann’s last blog post..Neu: E-Werkstatt für Selbständige, Existenzgründer und Freiberufler
April 29th, 2009 at 1:26 AM
this will work really well when i update the design on my blog… TY!
April 29th, 2009 at 5:12 AM
What happens when an author who is an admin comments? Obviously it will pick up that they are an author first, but should there perhaps be a style specifically for author-admins? Just a suggestion and nice work
April 29th, 2009 at 7:11 AM
@Jarryd
It would not end up being a problem, because the admin state is only checked if the commenter is not the author. You would need to have to separate If loops rather than an if/elseif in order to pick out author/admin.
May 3rd, 2009 at 8:51 AM
It’s the first time I commented here and I must say you share us genuine, and quality information for bloggers! Good job.
p.s. You have a very good template for your blog. Where did you find it?
May 12th, 2009 at 12:12 PM
Nice tutorial! Thank you. Some moments are still not clear to me but I will try to investigate them by myself.
May 23rd, 2009 at 5:41 PM
In my comment.php without only
So How?
Dhini’s last blog post..Zomaar cadeau (myn lieve man)
July 6th, 2009 at 8:33 PM
Muito Bom =D
July 10th, 2009 at 10:48 AM
Thanks took me ages to find this!
Now implemented in my comments
Thanks
.-= Ben´s last blog ..Update your EEE PC Bios from a USB Drive – A Guide =-.
July 18th, 2009 at 7:41 PM
This is a good trick but the problem is that if a malicious commenter enters the admin’s e-mail address, it will appear like it’s him, stealing not just the bg color but the gravatar too (i believe)
The latest version of wordpress gives classes like “comment-author-[name of author]” to the comments if the commenter is signed in. So you can play around with these classes on the css.
August 1st, 2009 at 2:48 PM
Nice tutorial! Thank you.
.-= mikle´s last blog ..Главная страница =-.
August 1st, 2009 at 9:28 PM
It all depends on your database structure. I myself, preffer using sort of a class checking script which I wrote some time ago. It requires some extra fields in database but works as good as this one does
August 21st, 2009 at 8:22 AM
wow, that is really great tutorial…. I will try to implement in my theme. I have just enabled it to be compatible with threaded comments.
.-= a_usman´s last blog ..One Email for Multiple Twitter Accounts =-.
December 18th, 2009 at 10:25 PM
Any way to make this into a plugin? not sure why, but i’ve modified my code to match above, included the css, but the changes dont take effect in my comments. Not sure why
February 17th, 2010 at 7:56 PM
@ a_usman
Can you please update us with the code fro new threaded template.
Thanx
Join the Conversation!
Remember: Life's not all doom and gloom, so please keep it constructive. If we've made an error or missed something big, please let us know! Learning is revisions, after all.