Support Forum

Get avatar outside of forum

FO Focus97
Focus97
Member

I saw an earlier thread about using sp functions outside the forum, and it alluded to needing to include forum files, variables, etc. I’m wondering how specifically to do this.

Is there a global variable to include so that I can echo sp_UserAvatar();? Or is there a file to include that will allow me to bootstrap sf functions – something akin to including wp-load.php?

7 Answers

New Answer

MP Mr Papa
Mr Papa
Member

whoops. looks like we did not think that through all the way.  We used to have a template tag for displaying the avatar outside the forum, but removed it in 5.0 in favor of the display template tag your referenced… problem is, as you discovered, its not available outside the forum…

you should be able to call:  sp_forum_api_support()

and then it should be available…  will have to consider the wrapper once again or make it more know about that function…

and for reference, you can get the details on the avatar function here:  http://codex.simple-press.com/codex/api/functions-and-tags/display-template-tags/common-view/sp_useravatar/

FO Focus97
Focus97
Member

Yep, I did see the codex article. I couldn’t glean much from it that would help me get the function working. As for now, I did try and declare the function above, but I’m still getting nothing on the page (in fact, the entire output of HTML now breaks after the functions).

 

I’m using this and wondering if I’m declaring the function you suggested correctly?

<div class=”bio-photo” id=”forum-bio-photo”>
                <?php
                sp_forum_api_support();
                echo sp_UserAvatar();
                ?>
            </div>

Currently the page is rendering white where the php begins (it’s a dev site, so I’m not terribly worried).

MP Mr Papa
Mr Papa
Member

well, you dont want the echo…  the sp_UserAvatar() function (as per the codex page) already outputs the data unless you set the echo=0 argument in which case it would be returned…

also, since you are not passing anything to the function, its assuming it will use the avatar of the currently logged in user…  is that what you want?

do you have a link to this example? would like to see if any output is generated just to make sure the function is really getting called (ie not missing an include file)…

if you want it for a specific user vs current logged in user, you would do something like

<?php
sp_forum_api_support();
sp_UserAvatar('context=user', $user);
?>

where $user is the user id or user email address that you want the avatar for…

YS Yellow Swordfish
Yellow Swordfish
Member

The function sp_forum_api_support() will not be available until SP version 5.0.5…

In the meantime please use the function sp_forum_ahah_support() which will eventually be deprecated although not that quickly.

FO Focus97
Focus97
Member

You guys are awesome. The ahah_support function with the avatar works perfectly to display on non-forum pages. I used just the sp_UserAvatar() to display the currently logged-in user’s avatar. Works brilliantly!

I just sent a PM to you both to provide access to the forum to view. Many thanks for the help.

YS Yellow Swordfish
Yellow Swordfish
Member

Will take a look…
Just so you know the sp_forum_ahah_support() function is going to be deprecated after 5.0.5 in favour of the more usefully named sp-forum_api_support() but it will be several versions before the old one disappears for good.