DISCLAIMER: this post is older than one year and may not be up to date with latest WordPress version.

When you have lots of comments on your WordPress blog, it is a good thing to give a special style to admin comments, like I do on CatsWhoBlog.com. But what about being able to give special styles to editors, contributors and subscribers comments?

To do so, simply open your comments.php file and replace your comments loop by this one :

<ol id="commentlist">
<?php foreach ($comments as $comment) : ?>
	<?php // The extra stuff to get commenter's role
	$user_id = $comment->user_id;
	$role = ( isset( $roles[$user_id] ) ? $roles[$user_id] : '' );
	?>
	<li class="<?php echo $role; ?>">
	<p>By <?php comment_author_link() ?> - <?php comment_date() ?></p>
	<?php comment_text() ?>
	</li>
<?php endforeach; ?>
</ol>

Once done, open yout style.css file and paste the following:

#commentlist li { border:2px solid white; } /* not logged or subscriber */
#commentlist li.administrator { border:2px solid red } /* blog admin */
#commentlist li.editor { border:2px solid blue } /* editor */

Many thanks to Ozh for this very interesting code!

By the way, as you probably know, today is black friday in the US and I have lots of great promo codes to share with all my readers:
WOOTHEMES : Get 50% off (No code needed)
STUDIOPRESS : 50% off on ANY theme packages with code SPTHX
GODADDY : $4 domains with the CJCBLACK09 code
HOSTGATOR : get a 20% discount using the code AUTUMN

3 Comments

  1. it’s really confusing !! it’s been a week and I’m not able to customize my comment form. and I just figured out that there is anther comment.php inside wp-includes! up till now I was doing all the modifications on the comments.php inside the theme folder.
    I’ll give a try with wp-includes/comments.php

    thank you for the post and thnk you Ozh for the code :)

  2. For some reason this didn’t work for me. I was able to display all comments as expected just not styled as per the code that went into my style.css.

    Puzzled.

  3. Thanks for nice code , but does it work in latest 3.3 version ? It doesn’t insert roles in the class for me :-(

Leave a Comment

Your email address will not be published. Required fields are marked *