Access logged in user’s id within weblog:entries tag
Posted: 28 May 2009 01:42 AM   [ Ignore ]
Jr. Member
RankRank
Total Posts:  60
Joined  2007-10-22

Hi there

Apologies if this has been covered before - I’ve searched but couldn’t find anything.

I’m trying to access the currently logged in user’s details using {exp:user:stats member_id=”{member_id}”} from within a weblog:entries tag pair, where the logged in user isn’t the author of the entry being viewed. All I’m seeing is the details of the author and not the logged in user.

Is there any way to just see the details of the logged in user and not the author of the weblog entry?

Cheers in advance,

Jim

Profile
 
 
Posted: 28 May 2009 02:29 PM   [ Ignore ]   [ # 1 ]
Administrator
Avatar
RankRankRankRankRank
Total Posts:  8223
Joined  2006-10-18

Hi Jim smile

Probably best not to have that loop inside the weblog:entries loop, especially if there’s no real reason to.

But whatever the case, this should solve your issue wink

{exp:user:stats member_id="{logged_in_member_id}"
 Signature 
Profile
 
 
Posted: 29 May 2009 06:57 AM   [ Ignore ]   [ # 2 ]
Jr. Member
RankRank
Total Posts:  60
Joined  2007-10-22

Thanks a lot Kelsey. I’ll give it a go.

Profile
 
 
Posted: 23 June 2009 03:00 PM   [ Ignore ]   [ # 3 ]
Newbie
Rank
Total Posts:  8
Joined  2009-05-09

I have precisely the same problem. Even using logged_in_user_id, the second instance of the user stats uses the same user as the one being viewed.

Unusually when hard-coding the member id, the right user is being displayed. Any ideas?

Profile
 
 
Posted: 24 June 2009 02:08 PM   [ Ignore ]   [ # 4 ]
Administrator
Avatar
RankRankRankRankRank
Total Posts:  8223
Joined  2006-10-18

dajaniel,

What does your code look like? smile

 Signature 
Profile
 
 
Posted: 29 June 2009 02:45 PM   [ Ignore ]   [ # 5 ]
Newbie
Rank
Total Posts:  8
Joined  2009-05-09

Well basically the page is in two columns: the ‘main’ column shows you the details of the user that you’re viewing:

<!-- member-profile -->
    <
div id="member-profile" class="span-14 append-1">
    
        
{exp:user:stats member_id={segment_3}}
    
        
<h2 class="yellow border">About {screen_name}</h2>
                
            <!-- 
avatar -->
            <
div class="span-5 colborder">
                
                
                <
class="avatar">
                    <
a href="{path='community/profile'}{member_id}">
                    
{if avatar_filename}
                    
<img src="{avatar_url}{avatar_filename}" width="190" height="190" alt="{screen_name}" />
                    
{if:else}
                    
<img src="/images/avatars/default.gif" width="190" height="190" alt="Avatar for {screen_name}" class="avatar" />
                    
{/if}
                    
</a>
                </
p>
                
                
            </
div>
            <!-- /
avatar -->
            
            <!-- 
about -->
            <
div class="span-8 last">
            
                
{if occupation && location}
                
<class="bottom"><strong>{occupation} from {location}</strong></p>
                
{/if}
                
                {if bio}
                
<p>{exp:html_strip}{bio}{/exp:html_strip}</p>
                
                
{if total_entries>0}
                
<p><a href="/?ACT=19&mbr;={member_id}" class="alt">&#8212;View all {screen_name}'s posts</a></p>
                
{/if}
                {
/if}
                 
                
<h3>Communications</h3>
                
                <
div class="span-2"><p><strong>Website</strong></p></div>
            
                <
div class="span-6 last">
                
                    <
p>{if url}<a href="{url}" title="Click here to visit {screen_name}'s website">{url}</a>{if:else}<em>Not specified</em>{/if}</p>
                
                </
div>
                
                <
div class="clear"></div>
            
                <
div class="span-2"><p><strong>Email</strong></p></div>
            
                <
div class="span-6 last">
                
                    <
p>{encode="{email}"}</p>
                
                </
div>
                
                <
div class="clear"></div>
                
                <
div class="span-2"><p><strong>Twitter</strong></p></div>
            
                <
div class="span-6 last">
                
                    <
p>{if twitter}<a href="http://twitter.com/{twitter}">{twitter}</a>{if:else}<em>Not specified</em>{/if}</p>
                
                </
div>
                
                <
div class="clear"></div>
                
                
{if total_entries>0}
                
                {embed
="community/.profile_blog_posts" author_id="{member_id}"}
                            
                {
/if}
                
            
</div>
            <!-- /
about -->
    
        
{/exp:user:stats}
        
    
</div>
    <!-- /
members --> 

While the sidebar to the right shows you your own avatar…

<!-- status -->
    
{exp:user:stats member_id="{logged_in_user_id}"
    
<div id="status" class="span-7 last">
    
        <
h2 class="blue border"><a href="{path='community/profile/{member_id}'}">Hello {firstname}</a></h2>
        
        <
div class="span-3 avatar">
            
{if avatar_filename} 
            
<a href="{path='community/profile/{member_id}'}"><img src="{avatar_url}{avatar_filename}" width="100" height="100" alt="Avatar for {screen_name}" class="avatar" /></a>
            
{if:else}
            
<a href="{path='community/profile/{member_id}'}"><img src="/images/avatars/default.gif" width="100" height="100" alt="Avatar for {screen_name}" class="avatar" /></a>
            
{/if}
        
</div>
        
        <
div class="span-4 last">
        
            <
ul>
                <
li><a href="{path='community/edit'}">Edit your profile</a></li>
                <
li><a href="{path='community/avatar'}">Upload an avatar</a></li>
                <
li><a href="{path='community'}">View members</a></li>
                <
li><a href="{path='logout'}">Log Out</a></li>
            </
ul>
        
        </
div>
    
    </
div>
    
{/exp:user:stats}
    
<!-- /status --> 


In this case, the sidebar will say ‘Hello….’ and the name of the member in the ‘main’ column, and also show the main editor.

Profile
 
 
Posted: 30 June 2009 10:06 AM   [ Ignore ]   [ # 6 ]
Member
RankRankRank
Total Posts:  139
Joined  2007-05-31

Sounds like a paring order issue. Not sure if embedding everything in a template will resolve which would allow you to pass in the members id.

You could try enabling php for the template in question and use something like:

<?php global $SESS; echo $SESS->userdata['member_id'];?> 

in place of {loggeed_in_member_id}.

Profile
 
 
Posted: 30 June 2009 10:17 PM   [ Ignore ]   [ # 7 ]
Administrator
Avatar
RankRankRankRankRank
Total Posts:  8223
Joined  2006-10-18

dajaniel,

In your “Main” column, you have this code:

{exp:user:stats member_id={segment_3}} 

Which should be:

{exp:user:stats member_id="{segment_3}"

Whether or not that’s the issue, it’s definitely wrong syntax wink

And second, in your “right” column, you have this:

member_id="{logged_in_user_id}" 

It should be this:

member_id="{logged_in_member_id}" 
 Signature 
Profile
 
 
Posted: 30 June 2009 11:55 PM   [ Ignore ]   [ # 8 ]
Newbie
Rank
Total Posts:  8
Joined  2009-05-09

I have just made those changes and the code looks precisely as above, but the same problem exists…

Any other ideas?

Profile
 
 
Posted: 01 July 2009 09:07 AM   [ Ignore ]   [ # 9 ]
Administrator
Avatar
RankRankRankRankRank
Total Posts:  8223
Joined  2006-10-18
{exp:user:stats member_id="{logged_in_member_id}" dynamic="off"

smile

 Signature 
Profile
 
 
Posted: 01 July 2009 09:10 AM   [ Ignore ]   [ # 10 ]
Newbie
Rank
Total Posts:  8
Joined  2009-05-09

At last! That did it.

Thanks.

Profile