ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Highlight Author's Comment

December 26, 2007 7:15am

Subscribe [3]
  • #1 / Dec 26, 2007 7:15am

    nocturnale

    12 posts

    I am finding it difficult to implement the ‘Highlight Author’s Comment’ using this guide from EE Wiki

    http://expressionengine.com/wiki/Highlight_Author_Comments/

    Is there any other easier way?

  • #2 / Dec 26, 2007 10:53am

    Boyink!

    5011 posts

  • #3 / Dec 28, 2007 8:58am

    nocturnale

    12 posts

    Michael, what if I choose not to use the ‘switch variable’ alternation of CSS? how will the code be different?

  • #4 / Dec 28, 2007 9:04am

    Boyink!

    5011 posts

    Rather than

    <div {If author_id=="1"}class="author_comments"{if:else}class="{switch="comment_dark|comment_light"}"{/if}>

    You’d remove the else part of the if statement and have:

    <div{If author_id=="1"} class="author_comments"{/if}>

    Looking again at the code, I used this on a one-person blog where the author_id was always known. If your authors will be variable, we’ll have to dig a bit deeper.

  • #5 / Dec 28, 2007 9:18am

    nocturnale

    12 posts

    but that only display the author’s comment, how about the ‘else’ statement to display ‘the others’ non-author?

  • #6 / Dec 28, 2007 9:22am

    Boyink!

    5011 posts

    All comments will be displayed.  This will just apply an “author_comments” class to the authors comment.

  • #7 / Dec 28, 2007 9:36am

    nocturnale

    12 posts

    I use this:

    <div id="commentEntries">
    {exp:comment:entries sort="asc" limit="20"}
    <div class="commentData">{count} - {url_or_email_as_author} wrote on {comment_date format="%d-%m-%y at %g:%i:%s %a"}</div>
    <div {If author_id=="1"} class="author_comment"{/if}>{comment}</div>
    <div class="other_comment">{comment}</div>
    {/exp:comment:entries}
    </div>

    But the page goes haywire.

  • #8 / Dec 28, 2007 9:46am

    Boyink!

    5011 posts

    Try simplifying the div structure by consolidating the class assignment into one if statement:

    <div id="commentEntries">
        {exp:comment:entries sort="asc" limit="20"}
            <div class="commentData">
                {count} - {url_or_email_as_author} wrote on {comment_date format="%d-%m-%y at %g:%i:%s %a"}
            </div>
            <div{If author_id=="1"} class="author_comment"{if:else} class="other_comment"{/if}>
                {comment}
            </div>
        {/exp:comment:entries}
    </div>
  • #9 / Dec 28, 2007 10:20am

    nocturnale

    12 posts

    Still not working… page returns blank.

    How would I know what my author_id is?

  • #10 / Dec 28, 2007 10:39am

    Boyink!

    5011 posts

    author_id is just a variable, so you can display it using

    {author_id}

    within the comment:entries tag.

  • #11 / Dec 29, 2007 2:59am

    nocturnale

    12 posts

    how do i find out which author is associated with what id?

  • #12 / Dec 29, 2007 9:21am

    Boyink!

    5011 posts

    You can either just use the author and author_id variables in your template in a test fashion, or if you go to the View Members area of the Control Panel and rollover the member name, the ID is the last part of the URL.

  • #13 / Jan 16, 2008 10:46pm

    Robert.S

    67 posts

    Hey Mike,

    I was playing with this and couldn’t get your code to work.

    Finally figured it out: In your example (which I cut & pasted from your blog)

    <div [If author_id=="1"]class="author_comments"[if:else]class="{switch="comment_dark|comment_light"}"[/if]>

    The first “if” statement has a capitalized “If”. Once I changed it, it was all fine. So it should read:

    <div [if author_id=="1"]class="author_comments"[if:else]class="{switch="comment_dark|comment_light"}"[/if]>

    By the way - how would you have different author styles for different authors? I couldn’t see anything about multiple conditionals in the EEDocs (but must admit haven’t searched the forums yet!).

    For example:

    <div [if author_id=="1"]class="author_comments"[if author_id=="2"]class="author_comments2"[if:else]class="{switch="comment_dark|comment_light"}"[/if]>

    </code></pre>

    Cheers!

    Robert

  • #14 / Jan 17, 2008 1:01am

    Robert.S

    67 posts

    I worked it out by myself (where is the “proud smiley”?)

    <div {if author_id=="1"}class="author_comments2"{/if} {if author_id=="11"}class="author_comments"{if:else}class="entry"{/if} >

    This seems to work beautifully at the moment ...

    Also @ Mike - my apologies I also see that the code on your blog has [] brackets rather than {}, which means any copy & paste wouldn’t have worked anyhow. The capitalized “if” could catch folks out though as it is hard to see the difference in the sans-serif font, so might be worth changing that.

    Cheers,

    Robert

  • #15 / Jan 17, 2008 6:28am

    Boyink!

    5011 posts

    Good catch on the capitalized if - I had had a note to change out the braces for brackets as I had published this before figuring out how to to prevent EE from parsing/rendering the example code.

    I’ve updated the example - thanks!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases