Hello Everyone,
I ran into an issue that probably has something to do with the settings, but I can’t seem to figure it out. This issue is only happening on the templates that output individual entries to the channels. Happening on all channels.
When a logged in user navigates to a entry template, in the header where I am outputting the logged in user, it switches and outputs the author of the entry. And when the logged in user adds a comment to the entry, it shows that the author of the comment is the author of the entry.
What’s going on here? And how can I fix it?
Thanks, Viktor.
Channel Entries Tag:
{exp:channel:entries channel="media" limit="1" require_entry="yes" url_title="{segment_4}"}
{if no_results}
{redirect="404"}
{/if}
My Template Code
{/exp:channel:entries}
Header Code:
<div class="user-name">Hi, {if logged_in}{exp:member:custom_profile_data}{first_name}{/exp:member:custom_profile_data}{if:else}Guest{/if}!</div>
Comments Code:
<div class="comments-container">
<h3>Comments:</h3>
{exp:comment:entries sort="asc"}
{if no_results} There are no comments for this article yet. {/if}
<div class="comment">
{if avatar}
{avatar_url}
{if:else}
/assets/images/user-icon.png
{/if}
<div class="comment-column">
<div class="comment-user-name">
{author}
</div>
<div class="comment-text">
{comment}
</div>
<div class="date-reply">
{comment_date format="%F %d, %Y - %H:%i"}
</div>
</div>
</div>
{/exp:comment:entries}
{if logged_out}
<div class="comment-login-area">
Please <a href="#" class="comment-login-link">Login</a> or <a href="#" class="comment-login-link">Register</a> to leave your comment.
</div>
{if:else}
{exp:comment:form}
<div class="comment-input-area">
<form action="post">
<textarea name="comment" rows="3" id="comment-input" placeholder="Leave a comment!">{comment}</textarea>
</textarea>
<button type="submit" class="submit-comment">Post Comment</button>
</form>
</div>
{if comments_disabled}
<div class="comment-login-area">
New comments for this article are currently disabled.
</div>
{/if}
{/exp:comment:form}
{/if}
</div>
Hi Victor,
Awesome, thanks for passing this along!
Few thoughts on the header front.
If possible, I’d recommend using the member global variables instead of the {exp:member:custom_profile_data} tag.
If preferred, to use the custom_profile_data tag (for which their are sold reasons to use). I’d recommend adding the member_id parameter to it. Something along the following lines.
<div class="user-name">Hi, {if logged_in}{exp:member:custom_profile_data member_id="{logged_in_member_id}"}{first_name}{/exp:member:custom_profile_data}{if:else}Guest{/if}!</div>
Does that do the trick for you?
Thanks,
-Tom Jaeger
Tom,
I appreciate you taking your time to help, however this didn’t work either. I did finally figure out why its doing that and got a solution, perhaps not the most streamlined but it works.
So the issue is {first_name} is a custom member field I created, and the entry author like all other logged in users also has the {first_name} field. Since my header with this {first_name} tag was inside the exp:channel:entries tag for the entry, it was outputting the authors {first_name} instead of the logged-in users {first_name}, even though it was inside of a variable.
So the solution was to use the exp:channel:entries tag twice, leaving the headers outside of the tags. Like this:
{exp:channel:entries channel="media" limit="1" require_entry="yes" url_title="{segment_4}"}
{if no_results}
{redirect="404"}
{/if}
Template Code
{/exp:channel:entries}
{main-header}
{mobile-header}
{exp:channel:entries channel="media" limit="1" require_entry="yes" url_title="{segment_4}"}
More Template Code
{/exp:channel:entries}
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.