繁体   English   中英

获取帖子作者图片 - Wordpress

[英]Get post author image - Wordpress

在 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>

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; ?>

尝试这个

<?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') );

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM