謝謝Rene Korss幫助解決問題幾乎每次都在那裏回答討論。檢查用戶是否有Gravatar [WordPress]
我想檢查發佈評論的用戶是否有頭像?如果用戶有頭像(意味着有gravatar帳戶)顯示gravatar頭像其他顯示圖像,我已經在其他部分定義。任何幫助將被appriciated。
我目前使用此代碼:
if(get_avatar()==1)
{
echo get_avatar($comment,$size='48',$default='<path_to_url>');
}
else
{ ?>
<img src="<?php bloginfo('template_directory'); ?>/img/admin.jpg" alt=""><?php
} ?>
輸出這個代碼只是工作else部分。如果我寫條件爲if(get_avatar())
,那麼只有當部分工作。
$註解的值:
stdClass Object (
[comment_ID] => 9
[comment_post_ID] => 104
[comment_author] => Navnish
[comment_author_email] => [email protected]
[comment_author_url] =>
[comment_author_IP] => 118.146.54.35
[comment_date] => 2015-09-23 14:33:11
[comment_date_gmt] => 2015-09-23 14:33:11
[comment_content] => this is comment by Admin
[comment_karma] => 0
[comment_approved] => 1
[comment_agent] => Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0
[comment_type] =>
[comment_parent] => 0
[user_id] => 1
)
當使用此代碼:
<?php
$avatar = get_avatar(get_the_author_meta('ID'), $size = '48', $default = bloginfo('template_directory').'/img/admin.jpg');
if($avatar !== false)
{
echo $avatar;
}
?>
了輸出像這樣:
輸出爲:
$avatar = get_avatar($comment->comment_author_email, $size = '48', $default = bloginfo('template_directory').'/img/admin.jpg');
if($avatar !== false)
{
echo $avatar;
}
向我們展示如何獲得'$ comment'。 –
$ comment是stdClass對象。我更新了有問題的$ comment的值 –