【问题标题】:display avatar for authors without post in wordpress在wordpress中为没有帖子的作者显示头像
【发布时间】:2017-08-02 21:00:45
【问题描述】:

如何获取尚未发布任何内容的作者的头像。 我为每个作者创建了一个特定页面,该页面显示作者的帖子,就像博客一样。 但是对于那些没有帖子的人,WordPress 会显示一个默认头像,而不是用户选择的个人资料图片。 这是我的作者信息代码:

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

<div class="nauthor-brief" style="">
    <?php echo get_avatar( get_the_author_meta( 'ID' ) , 60 ); ?>
    <div class="nauthor-brief-text">
    <h2> <?php echo $curauth->display_name; ?></h2>
    <p id="nauthor-description"><?php echo $curauth->user_description; ?></p>
    </div>
</div>

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    第 1 步:登录您的 WordPress 仪表板

    第 2 步:在左侧菜单的“外观”下,点击“编辑器”

    第三步:在“编辑器”页面,找到并点击页面右侧文件列表中的“content.php”

    第四步:找到这段代码:

    <div class="entry-meta">
    <?php twentyeleven_posted_on(); ?>
    </div><!-- .entry-meta -->
    

    ...并将其替换为:

    <div class="entry-meta">
      <? echo get_avatar( get_the_author_meta('user_email'), $size = '50'); ?>
    

    就是这样,你完成了!在本教程中,我们将作者的头像放在帖子的顶部(用于主页)。如果您想在帖子中的任何其他位置(或其他页面)显示作者的头像,只需使用以下代码:

    <? echo get_avatar( get_the_author_meta('user_email'), $size = '50'); ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-08
      • 1970-01-01
      • 1970-01-01
      • 2016-01-29
      • 2020-02-05
      • 2021-04-11
      • 2015-10-23
      • 1970-01-01
      相关资源
      最近更新 更多