WordPress author comments. Comments are the backbone of a blog. For a blogger, there are few things better than a nice, long stream of comments. As a reader, flicking through such streams can be as enlightening as reading the post itself. It can also be useful to easily spot the author’s comments, to read what they in particular had to say.

As an example, here on Pro Blog Design, each of my own comments looks slightly different to the adjacent comments. Achieving the same effect on your blog is easily done.

The method described here is specifically for WordPress users. Movable Type users should refer to this article, and TypePad users to this one.

Editing Your Comments Template

The code you’re looking to edit will be in comments.php. Search for the following line,

<?php foreach ($comments as $comment) : ?>

After it, paste the following (Remember to edit in your own email address!):

$PostAuthor = false;
if($comment->comment_author_email == get_the_author_email()) {
$PostAuthor = true;}
elseif($comment->comment_author_email == 'your@email.com') {
$PostAuthor = true;}

Now we can use PHP to add extra code to comments written by the blog author. Depending on the theme you are using, the comments area coding will look very different.

To demonstrate how the code may be used, I have taken the comments loop from the default theme, and added the necessary line to it. Have a look at it, and once you understand the principle, you can apply it to your own theme in whatever way you like.

<li <?php if($PostAuthor) {echo "class='authorcomment' ";} ?><?php echo $oddcomment; ?>id="comment-<?php comment_ID() ?>">
<cite><?php comment_author_link() ?></cite> Says:
<?php if ($comment->comment_approved == '0') : ?>
<em>Your comment is awaiting moderation.</em>
<?php endif; ?>
<br />
<small class="commentmetadata"><a href="#comment-<?php comment_ID() ?>" title=""><?php comment_date('F jS, Y') ?> at <?php comment_time() ?></a> <?php edit_comment_link('edit',' ',''); ?></small>
<?php comment_text() ?>

The above will add the class=’authorcomment’ to any comments written by the post author. You can then use CSS to style this class differently.

It will work on all comments using your email address. This means that you don’t have to be logged in to to leave a comment with the correct design.

Furthermore, when some bloggers allow others to guest post on their blog, they create an account for them in the blog itself. The above code will style those guest bloggers comments differently on the post they wrote.

Enjoy this post? You should follow me on Twitter!