this search result should work:
http://snipplr.com/view/52127/
you would need to add this function into functions.php of your theme, and call it where needed in your code;
<a href="link logout"> <img class="rotate" src="' . get_avatar_url( get_current_user_id() ) . '" width="205px"/> </a>
(you might also need to set the ‘size’ parameter;
untested)
http://codex.wordpress.org/Function_Reference/get_current_user_id
http://codex.wordpress.org/Function_Reference/get_avatar
First retrieve the ID of the logged user:
<?php
global $current_user;
get_currentuserinfo();
?>
Than to get the avatar you can do:
<?php echo get_avatar( $current_user->ID , 205); ?>
So your in your code, you could be something like this:
<?php
if ( is_user_logged_in() )
{
echo '
<a href="link logout"> <img class="rotate" src="' . get_avatar( $current_user->ID , 205) . '" width="205px"/> </a>
';
} else
{
echo '
<a href="link login"> <img class="rotate" src="http://localhost/design/images/h_login.png" width="100px" /> </a>
';
}
?>
thank @ayman and @alchymyth, i will try now !
@alchymyth
i test the code you give me, it is not my url avatart ?
@ayman, i tested your code, but it cannot display avatar :
Here my code editted
<?php
global $current_user;
get_currentuserinfo();
?>
<?php
if ( is_user_logged_in() )
{
echo '
<a href="link logout"> <img class="rotate" src="' . get_avatar( $current_user->ID , 205) . '" width="205px"/> </a>
';
} else
{
echo '
<a href="link dang nhap"> <img class="rotate" src="http://localhost/design/images/h_login.png" width="100px" /> </a>
';
}
?>
Sorry, my mistake.
the function get_avatar()
already output <img>
so it cant be a src
to another <img>
So the working code should be:
<?php
global $current_user;
get_currentuserinfo();
?>
<?php
if ( is_user_logged_in() ) {
echo '<a href="link logout"> <div class="rotate" width="205px">'. get_avatar( $current_user->ID , 205).'</a>';
} else {
echo '<a href="link dang nhap"> <img class="rotate" src="http://localhost/design/images/h_login.png" width="100px" /> </a>';
}
?>
i test the code you give me, it is not my url avatart ?
the result should be the avatar of whoever is logged in (at least this is how it works in my test site).
did you enter the function code from the linked source into functions.php of your theme?
in which template of your theme are you using the code?
@huynguoidacbiet, any updates on this? did the code I gave you or the one @alchymyth gave solve it for you?
Please give your feedback.