Highlighting Admin Comments

Written by: burt
Date: March 4, 2008
Filed under: Uncategorized
Trackback · Comment

In my other blog, I'm conducting "product support" and advice via the Comments section of each blog post. It's kind of unwieldy, but I want to do it that way in order to keep eyeballs on my site!

In order to make my answers to readers comments easier to find, I decided to try to highlight my comments only. I'm sure there are a few plugins that can handle this, but I decided to simply do a bit of coding in the comments.php file of my template, like this..

First of all, I decided I wanted to simply show an Avatar on my comments, so I foind the line of code like this;

PHP:
  1. <?php comment_text() ?>

and added 1 extra line above it, like this;

PHP:
  1. <?php if ($comment->user_id == 1) echo '<img title="Comment by Gary" xsrc="author.gif" align="right" />'; ?>

Many thanks to Sarah for the heads up on my previous code bug.  This above code should be good to go!  Thanks Sarah!

What this does is say "if the comment is made by 'admin', show an image, and align that image to the right. Aligning the image like this means the text of my comment would "wrap" around the image.

Easy as 123, for a nice way to highlight ones own comments.

Comments

  1. Comment by Toxie — March 4, 2008 @ 4:21 pm

    I'm sure you could've added some jscript in there somewhere ;)

  2. Comment by SarahG — March 4, 2008 @ 5:24 pm

    I tend to use the condition that the author's ID equals 1. Not sure if a commentator can put their name as 'admin' when commenting (although I've never tried that!) or perhaps you change your own name in your profile and 'admin' is no longer matched.

  3. Comment by burt — March 4, 2008 @ 7:05 pm

    Sarah - good point!  Code now fixed and attribution given! :D
    Tox - you smell, of wee.  HTH. ;)

  4. Comment by Chance — March 4, 2008 @ 8:07 pm

    Of course to highlight admin comments with a different background color it would be easy to use this bit of code to load an alternate style for the comment container of an admin post.

  5. Comment by burt — March 5, 2008 @ 5:32 pm

    Yep! That could be done really easily.

Leave a comment



Did you enjoy reading this?
Please consider subscribing to our RSS Feed!


Subscribe by Email
Get notified by email every time we update this Blog!


 

Subscribe (RSS)

Recent Comments

Sponsored By

What Others Are Saying