在img src Wordpress中显示头像图像

时间:2014-05-16 21:33:37

标签: php wordpress

我想在img src=""中显示登录的用户头像。我在Wordpress工作,我用这个代码显示但没有结果。

<img src="<?php global $userdata; get_currentuserinfo(); echo get_avatar( $userdata->ID, 46 ); ?>"

2 个答案:

答案 0 :(得分:0)

根据文档,结合get_avatar方法(46是大小):http://codex.wordpress.org/Function_Reference/get_currentuserinfo

该函数为$ current_user赋值,而不是$ userdata。这是您更新的代码

<?php
        global $current_user;
        get_currentuserinfo();
        echo get_avatar( $current_user->ID, 46 );
 ?>

但我想补充一点,您也可以使用方法get_current_user_id跳过此操作:http://codex.wordpress.org/Function_Reference/get_current_user_id

<?php
    echo get_avatar( get_current_user_id(), 46 );
?>

答案 1 :(得分:0)

这对我有用:

<figure class="alignnone">
                <?php
                    global $current_user;
                    if ( is_user_logged_in() ):
                    wp_get_current_user();     
                    echo get_avatar( $current_user->ID, 250 );
                    endif; 
                 ?>
</figure>
相关问题