亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

獲取文章作者圖片 - Wordpress

獲取文章作者圖片 - Wordpress

PHP
拉風的咖菲貓 2022-11-12 13:49:09
在 WordPress 中,我需要獲取創建帖子的作者的作者圖像。我試圖以這種方式獲取個人資料圖片,但沒有成功。這是我為獲取其他 author_meta_details 而編寫的代碼。<div class="row">    <div class="avatar col-md-3">        <picture class="avatar-circle">            <?php if($avatar = get_avatar(get_the_author_meta('ID')) !== FALSE): ?>            <img src="<?php echo $avatar; ?>" alt="">            <?php else: ?>            <img src="/wp-content/themes/lymited-child/images/avatar-image.png">            <?php endif; ?>        </picture>    </div>    <div class="author-details col-md-9">        <div class="author-name"><strong><?php echo get_the_author_meta('first_name'); ?></strong> - <?php echo get_the_author_meta('nickname'); ?>        </div>        <div class="author-summery"><?php echo get_the_author_meta('description'); ?>        </div>    </div></div>
查看完整描述

2 回答

?
慕容3067478

TA貢獻1773條經驗 獲得超3個贊

嘗試這個


<?php

   $get_author_id = get_the_author_meta('ID');

   $get_author_gravatar = get_avatar_url($get_author_id, array('size' => 450));


   if(has_post_thumbnail()){

      the_post_thumbnail();

   } else {

      echo '<img src="'.$get_author_gravatar.'" alt="'.get_the_title().'" />';

   }

?>

或刪除此條件并嘗試


echo get_avatar( get_the_author_meta('ID') );


查看完整回答
反對 回復 2022-11-12
?
千萬里不及你

TA貢獻1784條經驗 獲得超9個贊

get_avatar()返回<img>元素,因此您無需再次將其包裝img起來也需要包裝$avatar = ...到括號中,因為=優先級低于!==


嘗試更換這個


<?php if ( $avatar = get_avatar(get_the_author_meta('ID')) !== FALSE): ?>

   <img src="<?php echo $avatar; ?>" alt="">

有了這個


<?php if ( ( $avatar = get_avatar(get_the_author_meta('ID')) ) !== FALSE): ?>

    <?php echo $avatar; ?>


查看完整回答
反對 回復 2022-11-12
  • 2 回答
  • 0 關注
  • 109 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號