We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Logged in members, channel entry template and comments

How Do I?

avori's avatar
avori
60 posts
9 months ago
avori's avatar avori

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.

       
avori's avatar
avori
60 posts
9 months ago
avori's avatar avori

PS. The header is a partial, and outputs correctly on every other page. Also, in CP it shows that the correct user has added the comment.

       
avori's avatar
avori
60 posts
9 months ago
avori's avatar avori

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>
       
Tom Jaeger's avatar
Tom Jaeger
426 posts
9 months ago
Tom Jaeger's avatar Tom Jaeger

Thanks for posting this.

What version of EE and PHP are you currently running?

It would also be great if you could confirm ALL caching is disabled (we have seen things similar to this when pages are cached)

Thanks,

-Tom Jaeger

       
avori's avatar
avori
60 posts
9 months ago
avori's avatar avori

Hey Tom,

Im using EE 7.4.11, and PHP version: 8.1.10. BTW, I jsut figured the comments out. Should have used {name} instead of {author}. But the header i still an issue.

Thanks, Viktor.

       
Tom Jaeger's avatar
Tom Jaeger
426 posts
9 months ago
Tom Jaeger's avatar Tom Jaeger

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

       
avori's avatar
avori
60 posts
9 months ago
avori's avatar avori

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}
       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.