How to Distinguish Author Comments on Your Blog

Posted: 11/29/2007
In Tutorials, WordPress

One of my readers asked a good question today about how to differentiate author comments from those made by readers. It never occurred to me to write a tutorial on something like that, so thanks goes out to Chris Coyier for the idea. He has a nice looking blog and also writes about CSS (and Wordpress), so if you like this site you might want to check out his site as well!

Okay, getting started. Open up your comments.php file. (This tutorial assumes you’re using Wordpress as your blogging platform, by the way). Look for your opening OL tag. Using the default theme as an example, you should see something like this about 1/4 of the way down the page:

Depending on how your theme is set up, next you might see the statement within the LI tag which instructs WordPress to echo the comment if it’s approved. We don’t want to go straight into that yet. Instead, we’re going to insert some code telling WP to also check if it’s an author comment. Here’s how it looks in my comments.php file (I removed the Gravatar code for brevity’s sake):

1
2
<?php if ($comment->comment_author_email=="charity@designadaptations.com") echo 'author';
    else echo $oddcomment; ?>

This runs a comparison against whatever email address you entered as the administrator of your blog, so be sure you use that one if you want it to work. I you plan on having guest bloggers, you could also add this between echo ‘author’; and else echo:

1
else if ($comment->comment_author_email == "guest@email.com") echo 'specialguest';

Now you’ll have to add some styles to your CSS. The Web Developer Toolbar for Firefox is incredibly handy for this, because it’ll show you the elusive hooks used in WP’s core code which are used for identifying author comments. If you have it, hit Cmd+Shift+Y (Ctrl+Shift+Y on PC) and hover over a test author comment in your browser to see what I’m talking about.

Here’s how my style sheet looks:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
.cite { /*for reader comments */
float:left;
margin:0;
padding:5px;
font-size:1em;
width:120px;}
.cite img{padding-right:5px;}
.cite a{font-weight:bold;}
.comment_content{float:right; width:390px;}

li.author .comment_text{/*for author comments*/
color:#222;
border:solid 1px #69c;
background: #69c url(images/auth_comments.jpg) top left;}
li.author .cite a{color:#333!important;}
li.author .cite a:hover{color:#fff!important;}
li.author .cite .commentmeta a{color:#333!important;}
.author .comment_text p a {color:#fff !important;}

Notice I had to override the inherited rules (from the .cite class) by adding the !important keyword. You may or may not have to do this depending on your styling hooks and how they cascade.

That should be all there is to it! Having your comments visually distinguished from others is not only helpful to readers, but to you as the author if you need to refer back to something you said earlier. ;) It’s also a nice addition to the “curbisde appeal” of your site. Enjoy!

  • del.icio.us
  • Facebook
  • StumbleUpon
  • Digg
  • LinkedIn
  • Technorati
  • E-mail this story to a friend!

Thread {15 Responses}

Small Potato
11/29/2007

Nice tutorial. This will come in handy for my blog as more designers blog on it.

Mike
11/29/2007

wow, finally a tutorial on this that doesn’t require a doctorate degree in php and css. thanks!

Chris Coyier
11/29/2007

Wow! My wish has come true =)

This is an awesome tutorial, I’m going to work on implementing it my own blog right now, I’ll let you know how it goes.

Charity
11/29/2007

Thanks all, and hopefully I didn’t leave anything out! =)

Chris Coyier
11/29/2007

Check it out, I totally got it working.

Thanks Charity!

Charity
11/30/2007

Nicely done Chris, and you’re welcome! :)

Ehab
12/01/2007

Nicely done ! One of the easiest tuts I came across for stylin’ comments.

Well I found this very useful and it’s going in my del.icio.us bookmarks for when I redesign my blog! (ah, someday…) Thank you, Charity!

Lil DIva
12/17/2007

Thanks for the tutorial! There’a a plug in for this but I rather try your tip. One question: how do I add color to the commentors name like you have it here?

[...] How to differentiate author comment: Charity from DesignAdaptations.com wrote an useful tutorial about it. [...]

ari4u
8/06/2008

Would it be easier to use “the_author_email();” instead of hardcoding the email address in the code? This way, if the author changes email address in admin panel, there wont be a change to the code. Most probably should work for blogs with single author, not sure about multiple authors.

Let me know if i am completely off tangent.
Great tutorial btw.!

Nisha Ji
11/15/2008

Hi, It is great information. I will try it in my wordpress blog. Can I use this in my blogger blog also? If you have idea about blogger blogs then let me know.

Roger Hamilton
11/15/2008

Wow thanks! Was wondering how to do that!

Charity
11/16/2008

@Nisha – Well I haven’t used Blogger in forever, but I don’t think the same process applies. I guess it would depend on if there’s a conditional statement for the author’s comments. Can users even mod the PHP in Blogger templates? I always thought they were limited to CSS. (Set me straight if I’m wrong!) If you do have access to PHP, you could check to see how the IF statement is set up and edit it according to Blogger’s format… but I don’t know enough about it to be sure.

leksus
12/04/2008

Thanks for this tutorial, it will be in my blog in shot time.