Support » Fixing WordPress » Image display based on username?

  • Resolved Kahil



    Ok, so I am also using bbpress. There I have a plugin that lets people upload an avatar. When the image gets uploaded, it gets renamed to their username in all lowercase. I want to display that image in my wordpress sidebar but for some reason can’t get it to do so.

    Here is what I have…

    <img src=”/forum/avatars/<?php echo $strtolower($user->user_identity); ?>.jpg” alt=”avatar” />

    Can anyone help?

Viewing 15 replies - 1 through 15 (of 24 total)
  • First, you might want to put all bbPress questions in their forum. What is returned by that call?

    I have tried over there, but there aren’t many users over there to help. I figured that because I am trying to do this in WordPress, that this would be the best place to ask.

    it returns a full image url except for the file name.

    …/forum/avatars/.jpg is what gets out putted…

    The plugin uploads the image file to the avatars folder and renames it based on the username and changes it so that it is all lowercase, which the users are shared out between the wordpress and bbpress databases. All Being that the wordpress and bbpress usernames are the same, there shouldn’t be any issues there. In theory, I should just be able to what I had above right?

    Thanks for the help!

    <?php get_user_name( $user->ID ); ?>

    That didn’t work. It caused a fatal error… 🙁

    Are you trying to get the name while in a loop?

    no, in my sidebar… I didn’t know it hat to be. Ok, so now I know…is it possible to get it in the sidebar like that? So it uses the strtolower function to make it all lowercase?

    Thank you

    Moderator Samuel Wood (Otto)

    (@otto42) Admin

    Try this:
    <img src="/forum/avatars/<?php echo strtolower($user->user_identity); ?>.jpg" alt="avatar" />

    No $ in front of strtolower.

    it still isn’t doing so… 🙁

    Thanks for all the help guys

    maybe it does need the loop… does anyone know how that would work? I’ve tried using the look in my sidebar before but gave up on that because I never could get it to work correctly.

    Thank you

    Moderator Samuel Wood (Otto)

    (@otto42) Admin

    You don’t need to be in the Loop.

    Try using $user->display_name instead of “user_identity”.

    And this will be the picture of the logged in user, of course.. What, exactly, are you trying to do?

    That didn’t work neither….

    basically i have wordpress and bbpress using the same database, so all the tables are in the same place. I have a bbpress plugin called “avatar upload”. It lets users upload an avatar for their posts in the forum. This plugin will upload an image to a specific directory, in this case it is When it uploads the image, it renames the image to the user’s username in all lowercase. In theory, I should be able to do the same within wordpress as far as displaying the image. Being that both wordpress and bbpress are using the same usernames… I have a section of my sidebar set aside for user information. In there I would like to display a users avatar if they are logged in. Eventually I would like to make it so that if a visitor isn’t logged in, it will just either display nothing or display a default image.

    Thank you

    Moderator Samuel Wood (Otto)

    (@otto42) Admin

    What does it actually output? I’m looking at and see the img code in the page source, but since I’m not logged in, I clearly don’t see any image (no $user = no identity for me to have).

    What is in the source that *you* see when you are logged in?

    Maybe you should add this to the code:
    <?php $user = wp_get_current_user(); ?>
    That will make sure that the $user variable is set correctly.

    that didn’t work neither… 🙁

    it just says:

    I just tried it from within the loop and none of the above worked…





    THIS works.

    <img src="<?php echo strtolower($userdata->user_login); ?>.gif" alt="avatar" />

    ALL that is in that file is this:

    /* Don't remove this line. */
    echo $userdata->user_login;
    <img src="<?php echo strtolower($userdata->user_login); ?>.gif" alt="avatar" />
Viewing 15 replies - 1 through 15 (of 24 total)
  • The topic ‘Image display based on username?’ is closed to new replies.