<?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;?>
Run Code Online (Sandbox Code Playgroud)
我试图通过写这篇文章的作者的头像。我认为这会使这项工作有效,但它似乎没有输出正确的 url 并在图像上给我一个 404。
其他人用什么方法拉过头像?
我正在寻找一个答案,告诉我如何做到这一点,如果没有不显示的图像。
更新:
我已经尝试使用以下代码来完成这项工作:我应该提到我也在尝试在我的本地机器上进行这项工作。
echo get_avatar($authorId, 100);
Run Code Online (Sandbox Code Playgroud)
(变量使用get_the_author_id())
<?php echo get_avatar( $id_or_email, $size, $default, $alt, $args ); ?>
Run Code Online (Sandbox Code Playgroud)
哪里id_or_email需要。这在您的代码中缺失。更多https://codex.wordpress.org/Function_Reference/get_avatar
所以在你的代码中,尝试获取作者图片:
<?php echo get_avatar( get_the_author_meta( 'ID' ), 32 ); ?>
Run Code Online (Sandbox Code Playgroud)
您需要为“id_or_email”添加参数以获取适当的头像。对于 WordPress 2.7 或更低版本,您可以使用 get_the_author_id()。对于 WordPress 2.8 及更高版本,您可以使用 get_the_author_meta('ID')。该函数返回字符串或 false 布尔值。您可以通过比较返回值来判断您是否有头像。-获取头像
<?php while(have_posts()): ?>
<?php 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(); ?>
<div class="row author-post">
<div class="small-12 medium-4 column">
<?php if($avatar = get_avatar(get_the_author_meta('ID')) !== FALSE): ?>
<img src="<?php echo $avatar; ?>" alt="">
<?php else: ?>
<img src="/images/no-image-default.jpg">
<?php endif; ?>
</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 else: ?>
<?php the_content(); ?>
<?php endif; ?>
</div>
</section>
<?php endwhile; ?>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
26691 次 |
| 最近记录: |