One of my favorite parts of Raymond Chen’s blog, The Old New Thing, is how Raymond’s comments are all nicely highlighted. If you head over there, you’ll see what I mean. He can either write comments on an existing comment (which shows up as a contained box with a highlighted color) or just write a comment on the post, which also shows up highlighted. Either way, it makes it really easy to pick out Raymond’s comments in the resulting conversations about his posts. Since I was jealous, I decided to figure out how to do this. In this part, I’m going to show you how to add the second feature, which is making any author comment highlighted. Compared to the sub-comment, this is just a minor update to a few files.
First, we’re going to need a style for our author comments. In your theme directory, you should be able to find some type of css file. I’m using the default theme, and the file is located at:
/wp-content/themes/default/style.css
In this file, we are going to add a class for author comments. I wanted mine to have a noticeable blue highlight, like so:
.authorcomment {
background-color: #ccf;
}
I put it in the file right after the “.alt” class, since this is the class style used for alternating comment entries (every other comment is highlighted gray).
Now that we have the style set up, we need to make sure every author comment is of this class. To do so, find the file that handles comments. In the default theme, it is:
/wp-content/themes/default/comments.php
For the default theme, there is a loop in here that prints out each comment as an <li> inside of an <ol class=”commentlist”>. The <li> element is given the class $oddcomment, which alternates between “alt” and the empty string. We are going to replace the code at <li class=”…”> with this:
<li class="<?php
if($comment->comment_author_email
== get_the_author_email())
echo 'authorcomment';
else
echo $oddcomment; ?>"
id="comment-<?php comment_ID() ?>">
I found this code on this wordpress discussion of author tag highlights. Pretty straightforward stuff, but the results are quite effective. Just so you get an idea, I’ve posted a comment (from the same author account that I’m writing this post from) below, so you can see the highlight.