PureNews

PureNews is an amazingly sleek and powerful news theme with unlimited color variations.

View full feature list Check out the live demo Buy this theme today

How to make special “author” comments in wordpress

Posted by on 11th Jan 2008 Design & Coding 9 comments

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;
}
9 comments - Leave a reply
  • Posted by Cigar Jack on 11th Jan 2008

    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?

  • Posted by JamieO on 11th Jan 2008

    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.

  • Posted by Chris Coyier on 12th Jan 2008

    @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.

  • Posted by wasabi on 17th Jan 2008

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

    Before the loop of comment that generally it is

    <code></code>

    write this code

    <code>post_author); ?></code>

    and into the loop, but before the comment write:

    <code>comment_author_email == $authordata->user_email) $authcomment=true;

    ?></code>

    and change the Class in:

    <code><li class="<b>" id="comment-"></code>

    Now create e rules into css style.

    li.alt => normal comments

    li.alt-author => comments by authours of article