Display current logged in user's avatar outside of the loop?
题
I use the famous User Photo plugin for my Wordpress site. I want to display the current logged in user's avatar outside the loop. How is this possible?
The current code I use to display the author avatar inside the loop is:
<?php userphoto_the_author_thumbnail('', '', array(width => '40', height => '40')); ?>
Google did not give me much to go on. One person referred to this code:
global $authordata;
$authordata=get_userdata(get_query_var( 'author' ));
userphoto_the_author_thumbnail();
But it did not work. What is the solution?
解决方案
Use userphoto_thumbnail() and pass the user ID explicitly.
Usage:
userphoto_thumbnail($user, $before = '', $after = '', $attributes = array(), $default_src = '')
其他提示
Try the below code.
It will select the current logged-in user's email and then display the avatar.
<?php
wp_get_current_user();
$current_user_email = $current_user->user_email;
?>
<?php echo get_avatar( '$current_user_email', 40 ); ?>
Please try one of thes two.
userphoto($user, $before = '', $after = '', $attributes = array(), $default_src = '')
or
userphoto_thumbnail($user, $before = '', $after = '', $attributes = array(), $default_src = '')
Both function work same as userphoto_the_author_thumbnail
thanks
不隶属于 StackOverflow