x
 
Create New Page
 View Previous Changes    ( Last updated by vosSavant )

Highlight Author Comments

Question:

On the comments page, I would like to apply a different css class to all comments that are from the original author of the article. Feasible?

Answer:

This can be accomplished as long as you don’t mind some CSS in your <head>. Both the comments and weblog entry tags have {author_id} as a variable so try something like this around your comments

{exp:comment:entries} 
<div class="comment author{author_id}"
{comment} 
</div
{/exp:comment:entries} 

Then in the <head>, do something like this.

{exp:weblog:entries limit="1"

<style type='text/css'>
 .
author{author_id} { 
border
1px solid #CC0000; 

</style>

 
{/exp:weblog:entries} 


The extra ‘comment’ class is just what you would apply to all comments.

——————————————————————————————————
Edit by Mark Bowen - 26/03/08

One other add-on to this is by doing the following :

{exp:comment:entries} 
{if entry_author_id 
== author_id}
<div class="author-comment">{comment}</div>
{if:else}
<div class="comment">{comment}</div>
{/if}
{
/exp:comment:entries} 

You can then just have :

.author-comments {
        border
1px solid #ccc;
        
font-weightbold;
}
.comment {
        whatever you wish here
;

or whatever else you would like to do to just the authors comment. Slightly easier now that there is the entry_author_id variable.
——————————————————————————————————

Edit by vosSavant - 12/02/09

You need not include the CSS in your <head> section (you can add it to your CSS template), and can simplify the conditional a bit further, if you like:

{exp:comment:entries weblog="xyz"}
   
<li{if entry_author_id == author_id} class="author"{/if}>
      ...
comment data...
   </
li>
{/exp:comment:entries} 

The above code assumes that you are using a list to display your comments.

Category:Comments Category:Tips

Category:EE1

Categories: