2015-09-26 49 views
2

由於某種原因get_avatar($user_email, 125);不起作用。我無法弄清楚爲什麼。這是我在single.php代碼:無法在帖子中獲取當前作者頭像

<?php 
    $curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author)); 
    $user_email = $curauth->user_email; 
?> 

    <div class="author-box clearfix"> 
     <img class="author" src="<?php echo get_avatar($user_email, 125); ?> " width="125" height="125" alt="<?php echo the_author_meta('display_name' , $author_id); ?>" /> 
     <h4 class="title"><?php echo get_the_author(); ?></h4> 
     <p class="title"><?php the_author_meta('title'); ?></p> 
     <p class="info"><strong>M: </strong><?php the_author_meta('user_email'); ?></p> 
     <p class="info"><strong>W: </strong><a href="<?php the_author_meta('user_url'); ?>"><?php the_author_meta('user_url'); ?></a></p> 
    </div> 

回答

1

get_avatar文檔,它返回整個圖像元素的字符串。

檢索頭像<img>標記爲用戶,電子郵件地址,MD5哈希,評論或帖子。

你使用它的方式,你想要的圖像網址,所以使用get_avatar_url

返回:(false | string)我們找到的虛擬形象的URL,如果我們找不到虛擬形象,則返回false。

0
echo get_avatar(get_the_author_meta('email'), '90'); 

學習創建你自己的作家盒here