The majority of WordPress blogs look exactly the same. One of the things you can do to stand out is change the way author comments are displayed. This technique is great for improving readability as it allows your blog readers to quickly skim to comments by the author if, for example, they're trying to quickly find an author response to a question posed by another commentator.
You can see this strategy employed by Matt Cutts on his blog, and Kyle Eslick over at Hack WordPress. Here I'm going to show you how to give author comments their own look. This isn't the only way to do this, but it's the one I use…
I saw this explained by Kyle over at HackWordpress.Com, and the method he uses works, but it relies on checking for the author email, if the email matches the post author's email, the comments are styled as author comments. The problem with this is that I can enter any email when I write a comment on your blog, so what's to stop me from entering the author's email just to have my comments styled as author comments? Nothing. So here's a solution that styles author comments, but prevents anyone from posing as the post author.
Edit the WordPress comments.php File
The section of code we're going to edit begins on line 16 and goes through line 46, and looks like this:
We're going to change it to this:
By default, WordPress will tag the actual list item (<li>) of every other comment, starting with the first one, with class="alt". CSS allows you to apply multiple classes to one element by separating those classes with a space. You can read more about that here. So, what we want to do is leave the "alt" class in tact, but add an "author" class (or whatever you want to call it) to the author comments.
Explanation of Changes in comments.php
- Change line 17 from this:
This allows us to add in the "author" class without php throwing error messages at us.
- Now right after line 27, which says this:
We're going to add this snippet of code:
This will test for the user ID attached to a particular comment, and this is where this method outshines testing for the comment author email address. By default, WordPress attaches a user ID # to each comment. If the comment is not from a registered user, the comment will be assigned user ID #0. If you are the only author of your blog, your user ID # is probably 1, although you may want to check on that by following my instructions on how to check WordPress User ID. So, what the above snippet does is check that the user ID # for the comment is 1, if it is, it assigns both the "alt" and "author" comments to a variable named $commentclass. If the user ID is not 1, then just the "alt" class is assigned.
- Next we need to go down a bit and change this:
All that does is echo the $commentclass variable, which, if this is an author comment, is equal to "alt author" and if it's not an author comment, is just equal to "alt".
- Finally, go down a bit further and change this snippet:
Originally, that snippet said, "If the $oddcomment variable is empty (in other words = "), change the $oddcomment variable to 'alt'. Else (if it's not empty), change it to " (make it empty), for the next comment." This isn't directly related to the "author" class, but it sets up the $oddcomment variable so it's the way we need it to process it and the $authorcomment variables together.
Now it's time to style our author comments.
Adding the Author Comment Styles
Now you have something to work with in your stylesheet. All author comments will have the "author" class attached, so all you have to do is style it. How you do this is up to you, but here's how the comments are styled on a blog design I was working on (notice the li.author attribute second from the bottom):