无法在帖子中获得当前作者头像

时间:2015-09-26 09:34:29

标签: php wordpress avatar author

由于某些原因,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>

2 个答案:

答案 0 :(得分:1)

get_avatar文档中,它返回整个图像元素字符串。

  

检索用户,电子邮件地址,MD5哈希,评论或帖子的头像<img>标记。

您使用它的方式,您需要图片网址,因此请使用get_avatar_url

  

返回:( false | string)我们找到的头像的网址,如果我们找不到头像,则为false。

答案 1 :(得分:0)

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

学习创建自己的作者框here

相关问题