Question:
How can i style comments based off the author’s member id, or group?
Answer:
There are a number of ways to do this (...or, more ways to Rome)
Via EE conditionals (programming):
Set class particular class depending on group (class=“admin or class=“norm”)
<div {if member_group=="1"}class="admin"{if:else}class="norm"{/if}>
...comment...
</div>
Several groups
<div {if member_group=="1" OR member_group=="2"}class="admin"{/if:else}class="norm"{/if}>
...comment...
</div>
The above checks for the current (logged in) viewer to be member of a group (member_group is same as group_id)
and applies a class based on that. Note that member_group is preferred besides group_id as it also works inside
the {exp:weblog:entries} tag.
via CSS (cunning :-)
With this method you just put the author (or member_group) in HTML, and style it with css
<div class="comment comment_author{author_id}">
...comment
</div>
<div class="comment comment_author{member_group}">
...comment
</div>
Note that there are two classes defined here. The first class is “comment” and
it will always be applied, so we can make that the “base” style. Something like:
.comment {
background-color: #FFF;
}
The second class specifies a specific ID for the author or group of the comment which you can style with css.
Let’s say that we want to make non-registered “guest” comments (guest is author_id==0)
a different color (light grey) and administrator-comments light-blue:
.comment_author0 {
background-color: #ddd;
}
.comment_author1{
background-color: #bbf;
So, you’ve now covered three possibilities:
# Regular, (logged-in members) default “comment” class (author_id is empty)
# Guests with the “comment_author0” class
# Site admin with the “comment_author1” class
You can also, of course, add as many other specific ones corresponding
to other members that you want.
Category:Comments Category:Templates
