Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
1.1k views
in Q2A Core by

I'm trying to retrieve and display the avatar of the user logged and displayed in the sidebar for a more stylized page, but I had no result, can not get the avatar to print or display

function useravatar()
        {       
$user=qa_get_logged_in_userid();

 $this->output('<li class="qa-sidebar-user-li-avatar">'.qa_get_user_avatar_html($user['flags'], $user['email'], $user['handle'], $user['avatarblobid'], $user['avatarwidth'], $user['avatarheight'], qa_opt('avatar_users_size'), true).'</li>');
            }

you can helpme please, any idea?

by
this is the correct cod

function useravatar()
        {       
    $handle= qa_get_logged_in_handle();

    $user=qa_db_select_with_pending(
        qa_db_user_account_selectspec($handle, false)
    );

 $this->output('<li class="qa-sidebar-user-li-avatar">'.qa_get_user_avatar_html($user['flags'], $user['email'], $user['handle'], $user['avatarblobid'], $user['avatarwidth'], $user['avatarheight'], qa_opt('avatar_users_size'), true).'</li>');
            }


and this code put when you want to display the avatar


                        $this->useravatar();


sory for my english
by
Thanks for the code

2 Answers

+2 votes
by
edited by

You're using the qa_get_logged_in_userid() instead of qa_get_logged_in_user_cache which returns the global var $qa_cached_logged_in_user.

qa_get_logged_in_userid() returns only the userid.

You can use qa_get_logged_in_user_field($field) for each field you're looking for.

by
+1 This is perfect hook rather than passing id and all manually..
+1 vote
by

in qa-page-user.php it's done this way:

    require_once QA_INCLUDE_DIR.'qa-db-selects.php';

    $handle= qa_get_logged_in_handle();

    $user=qa_db_select_with_pending(
        qa_db_user_account_selectspec($handle, false)
    );

...