The MU forums have moved to WordPress.org

Avatars in the comments (4 posts)

  1. neyoung
    Member
    Posted 16 years ago #

    I'll just come right out and say it.

    I want to modify comments.php to display an avatar next to each users comments. How can I get each commentors username (not display name)?

    Background info... I have wpmu and bbpress databases integrated, but not functions. I'm using the bbpress Avatar Upload plugin to display avatars in my forums. I'd like to use the same avatars in my wpmu comments as I do in my forums. Here is some code that will display the commenter's avatar if I can get the commenter's username.

    global $user_identity;
    get_currentuserinfo();
    
    echo('<img src="/forum/avatars/' .
    FUNCTION_TO_GET_COMMENTERS_USERNAME() .
    '.jpg" alt="avatar" />');

    I just need to replace FUNCTION_TO_GET_COMMENTERS_USERNAME() with a real function that will return the commentors username.

    Any ideas?

  2. demonicume
    Member
    Posted 16 years ago #

    i think suelman(sp) is working on this already. check wpmduev and then go to his site. i believe its coming out in the next release.

  3. neyoung
    Member
    Posted 16 years ago #

    I ended up getting this to work, but not with nice neat functions, I had to use a mysql query.

    <?php
    $comment_author_dn = get_comment_author();
    $comment_author = $wpdb->get_row("SELECT <code>user_login</code> FROM <code>wp_users</code> WHERE <code>display_name</code> = '$comment_author_dn'");
    echo '<img id="comment-avatar" height="50" width="50" src="/forums/avatars/' . (empty($comment_author->user_login) ? "default" : $comment_author->user_login) . '" alt="avatar" />';
    ?>

    That code should find images for a user if they use a display name or just their login name.

    /shrug

    I haven't fully tested it, but it seems to work ok so far.

  4. lunabyte
    Member
    Posted 16 years ago #

    Try this. It works flawlessly, and is very easy to implement.

About this Topic

  • Started 16 years ago by neyoung
  • Latest reply from lunabyte