I have the following code to format the comment with different CSS and HTML depending on the author. (there is one admin and the user replying)
{exp:comment:entries sort="asc" limit="20" entry_id="{entry_id}" author_id="1"}
{name} My HTML code here {comment}
{/exp:comment:entries}
And then I have the same code for the user:
{exp:comment:entries sort="asc" limit="20" entry_id="{entry_id}" author_id="{author_id}"}
{name} My HTML code here {comment}
{/exp:comment:entries}
The reason I did this was because I cannot seem to just apply the conditionals to the name or author.
I tried all the options on https://u.expressionengine.com/article/a-primer-on-simple-conditionals
{if author_id == "1"}
Does not work.
The problem with the above code is that now I have all the admin replies first, and then all the user replies. They are not properly mixed in the order they come in. Because, of course, this is the way I’m parsing things, first all the comments from the specific staff user and next the logged user that added the entries.
Ideally, I would just have one code that displays all the comments on that entry and then just use conditionals to change the HTML around the author or comment. It seems conditionals are broken or just don’t work inside the exp:comment. Is there a way to apply different code depending on the author?
{exp:comment:entries sort="asc" limit="20" entry_id="{entry_id}"}
some conditional here to check the author_id and let me change the HTML tags around {name}
{name} My HTML code here {comment}
{/exp:comment:entries}
Ran a quick test on this one. It’s a bit hard to tell 100% why it wasn’t working on your install without taking a peek at it where it’s running. However the following does seem to work as intended. My guess is that it’s something to do with the quotes in the follow example VS what you posted above.
{exp:comment:entries sort="asc" limit="20"}
{if '{author_id}' == '1'}
***
{/if}
{comment}
<hr>
{/exp:comment:entries}
{exp:comment:form channel="blog" }
Sadly no, that does not work either.
Here is my code:
{exp:comment:entries sort="asc" limit="20" entry_id="{entry_id}"}
{if '{author_id}' == '1'}
HTML CODE {comment} HTML CODE
{/if}
{if '{author_id}' == '{author_id}'}
DIFFERENT HTML CODE {comment} DIFFERENT HTML CODE
{/if}
{/exp:comment:entries}
Not that I also tried just detecting one author and then using {if:else} instead. Seems to make no difference. I cannot apply a different styling to the comments from a different author.
If you take a look, what I want is to style the comments from the admin differently to the ones from the user. Latest EE version installed.
I found the problem.
When we check first for user 1 and then for the member that is posting the comment using {author_id}, this is actually pulling again the username 1. Makes sense. So author_id is actually again pulling the same user 1.
The solution is to use and excluding operator in the second field, such as:
{if author_id == '{author_id}' && author_id != '1'}
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.