Highlight the Author’s Comments

6th of June, 2008

I always neglect my personal site when working on other consuming side-projects.  Lately I've been hanging out at the wordpress support forums, because my latest project involves wordpress.  When I go there to search for answers, I invariably spend a minute and answer a couple of recent threads.

The mood of my reply to those threads varies with the quality of the answer I've just found for myself.  Not intentionally of course, it's just one of those cosmic-balance things :)

This is another in a burst of wordpress posts for me lately, partly because I'm hacking around with it, but also because a few of my most recent visitors have come from the wordpress forums via posts I've made there.

Christine asked me about making her own comments stand out from everyone else's.  This is one of the most widely-embraced features of all, I think, and with good reason.  It really makes it easy to find the official word amongst all the chatter (not that I have a big problem with excessive chatter here, mind you).

I directed her to a plugin called Highlight Author Comments, but plugins aren't really necessary for this sort of thing, if you're comforable with editing your theme.

The basic idea is to take the main comment element in your design, and give it a different CSS class.  This allows you to differentiate between one type of comment and another.  It's quite easy, if you can find where your particular theme puts this information in the first place, as all themes are different, this part is up to you, unfortunately.

Your theme's comment.php will is the place to look.  You might find either a div tag, or a list-item tag with the style of your comments applied to it, like this perhaps:

<li class="comment">

Our aim is to change that for the comments made by the post author, so it looks like the following, but only for that specific comment:

<li class="author_comment">

To do that, we'll need to put a little wordpress php magic in place of the 'class' attribute.

<?php
 if($comment->comment_author_email == get_the_author_email())
   $comment_class = 'author_comment';
 else $comment_class = 'comment';
?>
<li class="<?php echo $comment_class; ?>">

Now in your CSS file, just take the existing .comment definition and make a new one called .author_comment, which you can then change accordingly.

.comment {
    border: 1px solid blue;
    background-color: #88ccff;
    }
.author_comment {
    border: 3px solid red;
    background-color: #ffcccc;
    }

Of course yours will be a bit more complex, but that's the general idea.  Given the differences in themes, it's hard to be overly specific so something like this is best suited to those who are already up to their elbows in theme customisation.  For the rest, there's always that plugin I mentioned above.

You can get as creative as you like really, and it works on multi-author blogs just as well as it will on your personal blog, bearing in mind that if you're not the author of a post, your comments will not appear as though they're special, even though you might be the owner of the site and a total rock star.

Trust me, you'd have been bored if I didn't pad this post out with some back-story.

Sixteen Responses

  1. #1 7th of June, 2008 at 13:36

    Good feature! So, now I’m curious to see if you’ve implemented it here. =)

  2. #2 7th of June, 2008 at 14:48

    Long ago :) since day one actually… Which is probably why Christine asked.

    Mine are a bit more subtle than most, though… I think maybe I should consider pimping my comments a bit more.  Forget about modesty, I should put a regal background picture on mine :)

  3. #3 8th of June, 2008 at 16:14

    I’ve been wanting to do that for a long time. Thanks for this. 

    Modesty, schmodesty. You already know you are a rock star.  ;)

  4. #4 8th of June, 2008 at 16:31

    LOL, yeah, but it’s better when others say it :)

    (thank you!)

    I feel kind of stupid posting tiny wordpress tips here, but I’m just so consumed by everything wordpress lately.  I’m absolutely drowning in my new project, but I’ve already started thinking about the next one.

    Most people who have personal projects enjoy giving them attention and nurturing them… For me? Screw that.  I need a team to work on my personal projects for me. :)

    I have so many posts pending for this place, but since they’re long and involved topics chances are I’ll only get around to posting the light breezy stuff.

  5. #5 9th of June, 2008 at 13:47

    I’ll only get around to posting the light breezy stuff.

    The kind that blows my skirt up? {{snort}}

  6. #6 12th of June, 2008 at 21:30

    Hello Milorad,
    I’ve seen your great solutions in the forums section. I have a text messed up in my blog. Can you give me any advice?  I’ll be glad to place your link for the supports you’ll take.
    Best wishes

  7. #7 13th of June, 2008 at 00:53

    Sorry Luke, I donate plenty of time on the wordpress support forums.  You’ll have to catch me there.

  8. #8 16th of June, 2008 at 09:10

    Man, you’re like a pimp rock star, eh? ;)

  9. #9 16th of June, 2008 at 20:34

    A busy one apparently!

    Just think Karthik, you knew me before I was famous :)

  10. #10 20th of June, 2008 at 01:35

    I know! Now I feel all special.

  11. #11 30th of June, 2008 at 03:16

    Odlican sajt!

    Keep up with the good work!

  12. #12 11th of July, 2008 at 16:43

    Hey Milo!  how come your busy phases always seem to coincide with when I’m back on WLM!!  Its been weeks now. I shall wait patiently until the magical day when you return (and then no doubt, my computer shall die again, lol).

    Anyhow hope all is good and you’re able to come up for air occasionally :)

  13. #13 17th of July, 2008 at 01:40

    So, on a hiatus or something?

  14. #14 22nd of July, 2008 at 03:18

    I have been using the highlight authors comment plugin for awhile now, and it does work, but it’s a pain to have to go through the admin for css changes.

    I’ve been meaning to code a way to add an id or class to the author comment so I can style it in my css, but a quick google search and your code posted here and I’m done!

  15. #15 25th of July, 2008 at 23:22

    Happy to help Jon :)

    BJ, Metlin… unfortunately yes… things have been nothing short of *CRAZY* lately.  Usually is around the middle of year for me, as the transition between financial years leads my customers into an ordering frenzy.

    I’m looking forward to things settling down very shortly.

  16. #16 27th of August, 2008 at 13:11

    Good to hear from ya Milo.  Look forward to having you back in reality (well sort of…) soon.

Respond Now

Comments are Gravatar enabled

Fields marked * are required.

Allowed XHTML:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Close
E-mail It