您只需将当前用户的电子邮件地址传递到get\\u avatar()函数中。
<?php
$current_user = wp_get_current_user();
if ( ($current_user instanceof WP_User) ) {
echo get_avatar( $current_user->user_email, 32 );
}
?>
以下是一些具体链接:
get_avatar();wp_get_current_user();
以下是对您新问题的回应:
<?php
echo \'<img src="\'. get_the_author_meta( \'user_custom_avatar\', $current_user->ID, 32 ) .\'" />\';
?>
我之前给你的代码中分号太多了,这应该行得通。
编辑
这将使您的操作更加轻松。我不知道为什么我一开始没有这样做我将按您所希望的方式将其添加到您的示例片段中。
The Real Answer:
<a href="<?php echo get_author_posts_url($post->post_author); ?>" title="<?php the_author_meta( \'display_name\', $post->post_author ); ?>">
<?php if( get_the_author_meta( \'user_custom_avatar\', $post->post_author ) != \'\' ) { ?>
<img src="<?php the_author_meta( \'user_custom_avatar\', $post->post_author ); ?>" alt="" />
<?php echo $curauth->display_name; ?>
<?php } else {
$current_user = wp_get_current_user();
echo get_avatar( $current_user->user_email, $post->post_author ), \'80\' ); } ?>
</a>
对此表示抱歉。