Support Forum

Get avatar in spTopicView.php

SP sptab
sptab
Member

I’d like to make some changes on the way the avatar and rank icons are displayed in my theme.

Basically I am trying to modify spTopicView.php not to display the avatar icon if the avatar not been configured and it is left as default (guest/member).

I am testing the following in the post loop $spThisPostUser->avatar[‘uploaded’]

It works fine except if the user has changed his avatar in WordPress rather than in SP in which case $spThisPostUser->avatar[‘uploaded’] is still empty. Is there anyway to get the avatar in situation ?

 

Thank you.

7 Answers

New Answer

MP Mr Papa
Mr Papa
Member

I would suggest just grabbing the user avatar with the current template tag, sp_UserAvatar(), but instead of having it echo out, set the get=1 argument and you will  just be given the avatar data… and you can compare it to the default avatar filename and use or not use…

SP sptab
sptab
Member

Thanks for the tip.

Here is my function call, as it may help others.

$arAvatar=sp_UserAvatar(‘get=1&context=user’, $spThisPostUser);

MP Mr Papa
Mr Papa
Member

yes, that should get you the info… good work!

JO JohnnyNT
JohnnyNT
Member

In the same file (spTopicView.php) i am trying to do next thing: 

if(usergroup = 4){echo someimage}

 

This should go under avatar. Is it possible to do something like this (if it is, some hint please 🙂 )? 

MP Mr Papa
Mr Papa
Member

for each post, the $spThisPostUser object will contain:

 [memberships] => Array
        (
            [0] => Array
                (
                    [usergroup_id] => 2
                    [usergroup_name] => Members
                    [usergroup_desc] => Default Usergroup for registered users of the forum.
                    [usergroup_join] => 0
                )

        )

which is a list of memberships…   so you can check the usergroup_id..  and then echo what you want…

or you can simply use the:

sp_PostIndexUserMemberships();

template tag which will show the usergroup memberships directly for you…  see the function itself in the code for available arguments…

JO JohnnyNT
JohnnyNT
Member

Cool, thank you (again 😀 ) , i managed to make this:

 

 if ($spThisPostUser->memberships[0][‘usergroup_id’] == “4”) {$mesage = ‘This guy is cool’;} else { $mesage  =  ‘Not cool  ‘ ;}

echo  $mesage;