因此,下面的代码循环遍历我的文章并以列表格式显示帖子。下面是我使用的代码:
<?php while (have_posts()) : the_post(); ?>
<div class="one-sixth first"><?php the_post_thumbnail(); ?></div>
<div class="five-sixths"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></div>
<?php endwhile; ?>这是带有缩略图的图像:

这里是当没有帖子缩略图可用时,它只留下一个空空间:

发布于 2020-02-18 03:29:03
如果选中缩略图,如果已显示,否则将显示占位符图像。希望这能帮到你。
<?php
// Must be inside a loop.
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
else {
echo '<img src="' . get_bloginfo( 'stylesheet_directory' )
. '/images/placeholder.jpg" />';
}
?>https://stackoverflow.com/questions/60272935
复制相似问题