Skip to:
Content
Pages
Categories
Search
Top
Bottom

Using BuddyPress Avatars with wp_list_comments()


  • craftcore
    Participant

    @craftcore

    I’m using BP 1.5.5 and the current version of WordPress.

    I’ve been integrating my existing theme with BuddyPress, but I’m having trouble with user avatars constistently working across the site.

    I use the built-in wp_list_comments() function to list out my comments like this in comments.php:

    Comments

    Which results in a list of nested comments using a buddypress avatar if available, otherwise the gravatar.

    If you look at the comments section of this page ( http://craftcore.ca/2012-04-26-corny-sample-post/#comment-6 ), you’ll see that the first user who has a buddypress avatar is being upscaled from 50px to 75px for some reason, resulting in bad image quality. The second commenter has no buddypress avatar and the image is being pulled from gravatar.

    Any advice on making the buddy press avatar work properly? I’m not fussy on the size, as long as the quality is nice. I tried , but I don’t know how to make it work with wp_list_comments()…

    Thanks!

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

  • craftcore
    Participant

    @craftcore

    Oops, sorry, the code didn’t show.

    That should be:


    r-a-y
    Keymaster

    @r-a-y

    Hi,

    In your comments template, you should try using the BP avatar function:
    `
    if ( function_exists( ‘bp_core_fetch_avatar’ ) ) :
    echo bp_core_fetch_avatar( array(
    ‘item_id’ => THE_USER_ID,
    ‘type’ => ‘full’,
    ‘width’ => 75,
    ‘height’ => 75
    ));
    endif;
    `

    WordPress’ get_avatar() should work fine. For post/page comments, I would actually suggest using get_avatar() instead of bp_core_fetch_avatar() so that your site doesn’t break if you decide to turn off or stop using BuddyPress.


    craftcore
    Participant

    @craftcore

    Thank you for the replies!

    I’m not sure where to put the get_avatar() or the bPress avatar function though, because there’s no foreach statement on my theme to put it into. My comments.php just lists “ to output the code…

    I tried to download a buddypress theme that already had the avatars working properly using a foreach, but I can’t find one with nested comments working by default.

    Your wp_list_comments() call specifies the callback as a function called “mytheme_comment”, which is probably in your theme’s functions.php file. You’ll need to use these functions in there, or modify what you have already.

    For an example, look at the code block just below the phrase “You will need to define your custom callback function in your theme’s” on https://codex.wordpress.org/Function_Reference/wp_list_comments (get_avatar is used six lines from the top)


    craftcore
    Participant

    @craftcore

    Thanks for the tip, Paul! I have nice crisp avatars now; not a blurry pixel in sight!

    Strangely, calling get_avatar() still resulted in blurry pics. When I used the bp_core_fetch_avatar function, it worked perfectly.

    (See image of the results side by side: https://twitter.com/#!/pangepange/status/197016926789181441/photo/1/large )

    The function didn’t work as is, but when I changed item_id to “$comment->user_id”, the avatars worked on my theme.

    `<?php if ( function_exists( 'bp_core_fetch_avatar' ) ) :
    echo bp_core_fetch_avatar( array(
    ‘item_id’ => $comment->user_id,
    ‘type’ => ‘full’,
    ‘width’ => 75,
    ‘height’ => 75
    ));
    endif;
    ?>`

    Thanks so much for the help!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Using BuddyPress Avatars with wp_list_comments()’ is closed to new replies.
Skip to toolbar