WordPress.org

Forums

[resolved] Gravatar for Current User in Sidebar (6 posts)

  1. AdrianHanft
    Member
    Posted 8 years ago #

    Can someone help me with something I am trying to do on my blog? When an author is logged in, I would like to show his/her gravatar in the sidebar along with some of their profile information. I am new to WordPress (from Movable Type) and don't have a good grasp on the php of WordPress yet. Here is the code that I have tried without success:


    My Gravatar: <?php if (function_exists('gravatar')) {
    echo "<img src='";
    echo gravatar($curauth->user-email);
    echo "' alt='' class='gravatar' />";}
    ?>

    and


    My Gravatar: <?php if (function_exists('gravatar')) {
    $user_gravatar = wp_gravatar($curauth->user-email);

    echo "<img src='$user_gravatar' />";}
    ?>

    It seems like it should work, but then again I don't know what I am doing. Thanks for your help in advance!

  2. AdrianHanft
    Member
    Posted 8 years ago #

    I eventually got this to work. If anyone has a similar problem I recommend you upgrade to Gravatar2 and then use this code:


    <?php if (function_exists('gravatar')) { gravatar_image($userdata->user_email); } ?>

  3. AdrianHanft
    Member
    Posted 8 years ago #

    Actually the code above wasn't quite right. Try this:


    <?php global $user_email;
    get_currentuserinfo();

    gravatar_image($user_email);

    ?>

  4. carnold
    Member
    Posted 8 years ago #

    Can anyone inform me how to get some user info and place beside the gravatar?

  5. AdrianHanft
    Member
    Posted 8 years ago #

    carnold,

    I am probably the last person that should be giving advice about php and wordpress, but here is the code I used on my sidebar. It gives the user info (and gravatar) for the user who is signed in. On my site you have to sign in before you can see anything on the blog, so this works as a "my profile" type of feature. I hope it helps. Please somebody with more experience chime in because I can't elaborate on this at all. Sorry!

    <h2><?php global $userdata; get_currentuserinfo();
    echo($userdata->first_name);
    echo " ";
    echo($userdata->last_name); ?></h2>

    <?php global $user_email;
    get_currentuserinfo();
    echo "<img src='";
    echo gravatar($user_email);
    echo "' alt='' class='gravatar' width='80' height='80' ALIGN=RIGHT />";
    ?>

  6. carnold
    Member
    Posted 8 years ago #

    humm, this gets me my name and nickname. The rest of your code did not show up right. Can you repaste that here with spaces between the php code (like < ? php and so on). Many thanks
    OR
    send me the code via email to carnold5 at gmail dot com

Topic Closed

This topic has been closed to new replies.

About this Topic