php - Wordpress - 获取作者图片

标签 php wordpress

<?php while ( have_posts() ) : the_post(); ?>
    <section class="panel panel-white">
        <div class="row single-post-content">
            <?php if ($category_name !== 'Jobs') { ?>
                <h5 class="author-post__title"><?php the_author() ?></h5>
                <p><?php echo get_the_date(); ?></p>
            <?php }

            the_content();

            if ($category_name !== 'Jobs') { ?>
                <div class="row author-post">
                    <div class="small-12 medium-4 column">
                        <img src="<?php  echo get_avatar(); ?>" alt="" />
                    </div>
                    <div class="small-12 medium-8 column">
                        <h5 class="author-post__title"><?php the_author() ?></h5>
                        <p>
                            Lorem Ipsum has been the industry's standard dummy text
                            ever since the 1500s, when an unknown printer took a
                            galley of type and scrambled it to make a type specimen
                            book. It has survived not only five centuries, but
                            also the leap into electronic typesetting, remaining
                            essentially unchanged. It was popularised in the 1960s
                            with the release of Letraset sheets containing.
                        </p>
                    </div>
                </div>
            <?php } ?>
        </div>
    </section>
<?php endwhile;?>

我试图通过写这篇文章的作者的头像。
我认为这会使这项工作有效,但它似乎没有输出正确的 url 并在图像上给我一个 404。

其他人用什么方法拉过头像?

我正在寻找一个答案,告诉我如何做到这一点,如果没有不显示的图像。

更新:

我已经尝试使用以下代码来完成这项工作:我应该提到我也在尝试在我的本地机器上进行这项工作。
echo get_avatar($authorId, 100); 

(变量使用 get_the_author_id() )

最佳答案

<?php echo get_avatar( $id_or_email, $size, $default, $alt, $args ); ?> 

哪里id_or_email是必须的。这在您的代码中缺失。更多 https://codex.wordpress.org/Function_Reference/get_avatar

所以在你的代码中,尝试获取作者图片:
<?php echo get_avatar( get_the_author_meta( 'ID' ), 32 ); ?>

关于php - Wordpress - 获取作者图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40751664/

相关文章:

javascript - 如何使用 javascript "access only"链接

html - 将 Adob​​e Illustrator 模板转换为 Wordpress 主题?

css - 无法将一个 div 堆叠在另一个 wordpress 函数之上

php - while循环只检索一个结果

windows - PHP 进程 ram 和 cpu 使用率 (windows)

php - MySQL 简化了一个 Select & Update 命令

JavaScript - 必须刷新页面才能显示粒子 slider Logo 效果

php - SF2 : Configure a service that gives a new object instance each time

php - 除了基本的商店功能外,还需要一个 wordpress 购物车插件来满足以下要求。有什么好的建议吗?

javascript - 排队样式和脚本 WordPress 不起作用