» Design & Coding » How to make special “author” comments in wordpress

Chris CoyierHow to make special “author” comments in wordpress

Written by Chris Coyier from CSS-Tricks on January 11, 2008

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;
}
Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Bumpzee
  • E-mail this story to a friend!
  • Ma.gnolia
  • Print this article!
  • Reddit
  • StumbleUpon
  • Technorati
  • TwitThis
Written by Chris Coyier from CSS-Tricks on January 11, 2008 | Filed Under Design & Coding
Unique Blog Designs

9 Responses so far | Have Your Say!

  1. Cigar Jack  |  January 11th, 2008 at 9:46 pm #

    Cigar Jack - Gravatar

    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  |  January 12th, 2008 at 12:33 am #

    JamieO - Gravatar

    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 (Post Author)   |  January 12th, 2008 at 2:46 pm #

    Chris Coyier - Gravatar

    @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  |  January 17th, 2008 at 5:29 am #

    wasabi - Gravatar

    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

Trackbacks to 'How to make special “author” comments in wordpress'

  1. Le ultime notizie più succulente dal mondo dei blog - Edizione del Gennaio 2008 | MondoBlog
  2. Рекомендация по выделению администраторских комментариев среди других » Как бесплатно создать сайт и блог? Журнал для веб-мастеров и бл
  3. This Month In SEO - 1/08 - TheVanBlog
  4. The Ignorantsoup - Maki, My Life and Me
  5. Reboxetine.

Leave Feedback

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>