Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to display specific user's avatar?

  • @mrk-1

    Participant

    Im working on a widget to display a specific user’s avatar and status from bp’s “status update”.

    A current user’s status can be displayed with: get_usermeta( user_id, 'bp_status' );.

    But how to display a user’s avatar?

    I thought bp_displayed_user_avatar() might be an approach, but bp_displayed_user_avatar(user_id) doesn’t work … Or is there another template tag?

    Thanks in advance!

Viewing 7 replies - 1 through 7 (of 7 total)
  • @lisasabinwilson

    Participant

    Give this a shot – it links the user avatar (by user ID) to that member’s profile page (this example pulls from the user with the ID of 3) –

    <?php global $bp; ?>
    <a href="<?php echo bp_core_get_userurl($userid=3) ?>"
    title="<?php bp_core_get_user_displayname( $userid=3, true ) ?>">
    <?php echo bp_core_get_avatar( $userid=3, 1 ) ?></a>

    I bet there’s a cleaner way to go about it – but it should get ya started :)

    @mrk-1

    Participant

    Thank you Lisa, that rocks.

    So if you want to have an author widget in a user’s blog sidebar, here’s an approach:

    <?php
    $userid = 2; // set user_id
    $bp_status = get_usermeta( $userid, 'bp_status' ); // get_usermeta(userid,'metakey');
    if( $bp_status['content'] && is_home() ){ // if there is a status set && we are on blog's home
    ?>
    <!-- Status Updates -->
    <li>
    <div class="sidebarbox">
    <h2>Autor</h2>
    <ul>
    <span class="alignleft">
    <a href="<?php echo bp_core_get_userurl( $userid ) ?>"
    title="Profil von <?php echo bp_core_get_user_displayname( $userid, true ) ?>">
    <?php echo bp_core_get_avatar( $userid, 1 ) ?></a>
    </span>
    <?php echo $bp_status['content']; ?>
    <span style="display: block; clear: both;"><!-- clear --></span>
    </ul>
    </div>
    </li>
    <?php } // endif ?>

    Am I really the first one who thought about this?

    A “cleaner” way would be highly welcome.

    @lisasabinwilson

    Participant

    M@rk – seems so :) Looks pretty much how I’m doing it for a client site currently – – they have 4 main Contributors who publish to the main blog and they wanted a section in the sidebar called “Contributor Corner” that displays each of the 4 contributor avatars (clickable to their profile page) shown next to their latest status update from their profile.

    Works :)

    @johnjamesjacoby

    Keymaster

    I’ve done something like this in the past… It all depends on which file you’re trying to do this in, and in which loop so you know what data you have available to you…

    In a post loop, you can use the global $authordata to get the authors ID.

    // Code borrowed from bp_adminbar_authors_menu()
    function bp_author_link() {
    global $authordata;

    // Get author's data BuddyPress style
    $author = new BP_Core_User( $authordata->ID );

    echo '<a href="' . $author->user_url . '">';
    echo $author->avatar_mini;
    echo ' ' . $author->fullname;
    echo '<span class="activity">' . $author->last_active . '</span>';
    echo '</a>';
    }

    This way it’s tucked in a function that can be re-used in various other pages and ways.

    @mrk-1

    Participant

    Thank you so much John James –

    since functions like bp_core_get_avatar() are lost in BP 1.2*, you definitely made my day!

    *) undefined even with BuddyPress backwards compatibility plugin

    Please permit one more question: how can I fetch/ display a specific user’s latest update (instead of $author->last_active, like in your example – now, in BP 1.2)!?

    I’ve been looking through bp-core-classes.php, searching for something like

    $author = new BP_Core_User( $user_id);
    echo $author->user_update;

    to work… no success.

    Thanks in advance!

    @mrk-1

    Participant

    @ankurm

    Member
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to display specific user's avatar?’ is closed to new replies.
Skip to toolbar