How to make special “author” comments in wordpress

Here is a quick little tip for WordPress on how you style your author comments differently from other comments on your blog. Thanks to Charity at Design Adaptations for first explaining to me how to do this.

In your comments.php file you will likely have a line like this, which is right at the beginning of the “comment loop” which makes the list item for each comment:

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

Replace that with this:

<?php if (get_comment_type() == "comment"){ ?>
<li class="<?php if ($comment->comment_author_email == "myemail@mysite.com") echo 'author';
else echo $oddcomment; ?> item" id="comment-<?php comment_ID() ?>"></li>

Make sure to replace myemail@mysite.com with the email of your administrator account in WordPress. All this does is check the email of the comment author against that email and if it matches it applies the class “author” to the list item. Now you have your hook, which you can use in your CSS to apply styling.

li.author {
  background: red;
}

Chris Coyier Written by Chris Coyier from CSS-Tricks
Posted on January 11th, 2008 and filed under Design & Coding
Do not forget to subscribe to our RSS feed for updates
  • Digg This Post
  • Tweet This Post
  • Stumble This Post
  • Submit This Post To Delicious
  • Submit This Post To Reddit
  • Submit This Post To Mixx

9 Responses to “How to make special “author” comments in wordpress”

Author comments are in a darker gray color for you to easily identify the posts author in the comments

  1. Cigar Jack says:

    Great tip, but what if you have a site with multiple authors? Can you set it to check against the post author email address somehow?

  2. JamieO says:

    Could you verify against the user level of a commenter? Similar line of thinking to how to filter yourself out of google analytics reports has done.

  3. Chris Coyier says:

    @Cigar Jack: Yep, charity covers that in her article I linked to. Basically you just need to put an else statement in there:

    else if ($comment->comment_author_email == “guest@email.com”) echo ’specialguest’;

    @Jamie0: Yep, I’m sure that’s possible. That article you linked to had the WordPress PHP commands there to get the user level, so just write some IF statements for the different levels that apply different classes based on level.

  4. wasabi says:

    I prefer use a different method. For me is very more simple use this hack:

    Before the loop of comment that generally it is

    write this code
    post_author); ?>

    and into the loop, but before the comment write:
    comment_author_email == $authordata->user_email) $authcomment=true;
    ?>

    and change the Class in:
    <li class="" id="comment-">

    Now create e rules into css style.
    li.alt => normal comments
    li.alt-author => comments by authours of article

Comments are closed.

Comments are closed since this post is older than 30 days. However, you can continue this discussion in our popular Blogging Forums

Subscribe To BloggingTips Via RSS Subscribe To Blogging Tips Via Email Follow Us On Twitter Find Out More About Our Newsletter
 

Blogging Tips Sponsors

Blogging Tips Newsletter

 

Blogging Tips Sponsors

 

Latest from the Blogosphere