Skip to:
Content
Pages
Categories
Search
Top
Bottom

Getting the BP post author avatar outside of loop.

  • Avatar of enderpal444
    enderpal444
    Participant

    @enderpal444

    Ok Im using the wp-postratings plugin which allows you to show the a single highest rated post from a category. The problem is it shows the title and I want it to show the avatar. of the BP author. I found where to change it but I can’t figure out what to use to get the BP avatar. Heres the snippet of code in question.

    ‘if (strpos($template, ‘%POST_TITLE%’) !== false) {
    $author_id=$post->post_author;
    $post_title = the_author_meta( ‘avatar’ , “$author_id” );
    if ($max_post_title_chars > 0) {
    $post_title = snippet_text($post_title, $max_post_title_chars);
    }
    $value = str_replace(“%POST_TITLE%”, $post_title, $value);
    }’

    I had already changed the value of $post_title to what it is now but that obviously isn’t working. I just need to $post_title to equal the url of the bp author avatar or get the image all together. It’s later called in the template by using %POST_TITLE%. Hope that makes sense and thanks for any help.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Use WordPress’ get_avatar() function: http://codex.wordpress.org/Function_Reference/get_avatar

    Avatar of enderpal444
    enderpal444
    Participant

    @enderpal444

    @DJPaul Ok I changed it to this but alls I get now is a regular gravatar and not the actual avatar of the author.

    ‘if (strpos($template, ‘%POST_TITLE%’) !== false) {
    $post_title = get_avatar( $post_id, 50);
    if ($max_post_title_chars > 0) {
    $post_title = snippet_text($post_title, $max_post_title_chars);
    }
    $value = str_replace(“%POST_TITLE%”, $post_title, $value);’

    Avatar of enderpal444
    enderpal444
    Participant

    @enderpal444

    @DJPaul Ok I changed it to this but alls I get now is a regular gravatar and not the actual avatar of the author.

    ‘if (strpos($template, ‘%POST_TITLE%’) !== false) {
    $post_title = get_avatar( $post_id, 50);
    if ($max_post_title_chars > 0) {
    $post_title = snippet_text($post_title, $max_post_title_chars);
    }
    $value = str_replace(“%POST_TITLE%”, $post_title, $value);’

    You need to give it the post author’s ID, not the post’s ID :)

    You need to give it the post author’s ID, not the post’s ID :)

    Avatar of enderpal444
    enderpal444
    Participant

    @enderpal444

    @DJPaul Ha ok I got it working. Just have one more question and that’s how do I display it larger than 50px without it distorting the image? It displays larger on the members profile without distorting but when I set the code below to “96″ the image came out fuzzy.

    ‘if (strpos($template, ‘%POST_TITLE%’) !== false) {
    $userid = $post->post_author;
    $post_title = get_avatar( $userid, 96);
    if ($max_post_title_chars > 0) {
    $post_title = snippet_text($post_title, $max_post_title_chars);
    }
    $value = str_replace(“%POST_TITLE%”, $post_title, $value);
    }’

    Avatar of enderpal444
    enderpal444
    Participant

    @enderpal444

    @DJPaul Ha ok I got it working. Just have one more question and that’s how do I display it larger than 50px without it distorting the image? It displays larger on the members profile without distorting but when I set the code below to “96″ the image came out fuzzy.

    ‘if (strpos($template, ‘%POST_TITLE%’) !== false) {
    $userid = $post->post_author;
    $post_title = get_avatar( $userid, 96);
    if ($max_post_title_chars > 0) {
    $post_title = snippet_text($post_title, $max_post_title_chars);
    }
    $value = str_replace(“%POST_TITLE%”, $post_title, $value);
    }’

    Avatar of Nm
    nm
    Participant

    @nahummadrid

    is there a way to set the get_avatar size higher than 96?

    I have just been using this
    `post_author) ) : ?>

    <a href="”>

    `
    ..to get the large avatar photo of the author to show it on the author posts archive template and other places. But recently i’ve been switching some of these to “get_avatar” where thumb sizes are less than 96px.

    The only thing is that the large avatar size needed on the author template isn’t best quality when using get_avatar (150px).

    So is there a way to define the get_avatar full size to be the same as the bp default full avatar size.

    Avatar of r-a-y
    r-a-y
    Moderator

    @r-a-y

    You shouldn’t use the members loop if you don’t need it.

    A more efficient call is using bp_core_fetch_avatar() and setting the parameters there. (Make sure you use a function_exists() call if you use this approach.)

    You can alternatively filter get_avatar() as well using bp_core_fetch_avatar() as well.

Viewing 9 replies - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.