Highlighting Author Comments in Wordpress

So one of the cooler Wordpress hacks is allowing the articles authors comments to be highlighted. This helps the authors suggestions and comments stick out from the rest, allowing a more useful discussion. Below are two methods of achieving this effect.

So here it is for all of your Wordpress hacking needs.

First thing you are going to need to do is open your current themes stylesheet. To do this log into your admin control panel, typically located at http://yourblogurl.com/wp-admin. From there click on Design Tab followed by the Theme Editor link. Once in the theme editor you’ll see links along the right and you should see a file named style.css (this is a required file for Wordpress Themes so it’ll be standard for all your themes). Click on the file and it’ll bring it up in the editor for your edit.

add this code anywhere in your stylesheet:
.authorcomment {
background: #131313;
}

Now this code can be edited to your liking based on the CSS look you are going for.

Next you’ll need to need to open up your comments.php for editing. (follow the sames steps you used to find the style.css).

You should find the following code:

<li <?php echo $oddcomment; ?>id="comment-<?php comment_ID() ?>">

And you’ll want to replace it with this:

<li <?php if ($comment->user_id == 1){ $oddcomment = 'authorcomment'; } echo "class=\"" . $oddcomment . "\"";     ?>id="comment-<?php comment_ID() ?>">

Now if you wanted the other of the post to be dynamic (say you share a blog with multiple authors) you would use this instead of the code above:

<li <?php if ($comment->user_id == $post->post_author){ $oddcomment = 'authorcomment'; } echo "class=\"" . $oddcomment . "\"";     ?>id="comment-<?php comment_ID() ?>">

Thats it! Enjoy.

3 Responses to “Highlighting Author Comments in Wordpress”

  1. Php Website Editor Says:

    Good site I \”Stumbledupon\” it today and gave it a stumble for you.. looking forward to seeing what else you have..later

  2. Julián Rodriguez Orihuela Says:

    Great job!

    I leave my version here, which marks any registered user’s comment as class ’staff’:

    <li <?php if ($comment->user_id != 0){ $oddcomment = ‘class="staff" ‘; } echo $oddcomment; ?>id="comment-<?php comment_ID() ?>">

Trackbacks

  1. New Wordpress Hack | CalebAWhite.com

Leave a Reply