2017-08-08 42 views
0

我想顯示用戶的頭像在我的網頁,我指的是這裏的教程:link。我希望它能像這樣工作:WordPress的get_avatar()不工作

<h2>Members</h2> 
<?php echo get_avatar('[email protected]', 30); ?> 

但沒有任何顯示。這裏'[email protected]'實際上位於網站的'用戶'列表中,並且我已確認'Show Avatar'選項已被選中,如教程中所示。但不知何故,頭像沒有出現。

我也嘗試將'[email protected]'更改爲某個用戶ID(同樣,它肯定存在於'用戶'列表中);還是行不通。我做了呈現頁面後,代碼檢查,發現它的代碼註釋處理:

<!--?php echo get_avatar('[email protected]', 30); ?--> 

誰能給我如何解決這個問題的提示?

+0

看起來你正在嘗試運行PHP的內部。 html文件 – Und3rTow

回答

0

試試下面的方法,

1.

<?php 

echo get_avatar(get_the_author_email(), '128', '/images/no_images.jpg', get_the_author()); 

?> 

2.

<?php 

echo get_avatar(get_the_author_meta('ID'), 60); 

?> 

3.

<?php 

$current_user = wp_get_current_user(); 

if (($current_user instanceof WP_User)) { 
    echo get_avatar($current_user->user_email, 32); 
} 

?>