php - 如果没有缩略图,则忽略缩略图空间
问题描述
所以我有下面的代码循环遍历我的帖子并以列表格式显示帖子。这是我正在使用的代码:
<?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; ?>
解决方案
如果检查缩略图是否已显示,否则显示占位符图像。希望这对您有所帮助。
<?php
// Must be inside a loop.
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
else {
echo '<img src="' . get_bloginfo( 'stylesheet_directory' )
. '/images/placeholder.jpg" />';
}
?>
推荐阅读
- database - 在数据库表中存储 Laravel 5.6 查询日志
- date - 想要在表中自动插入当前日期当发布请求时
- hyperledger-fabric - Hyperledger Fabric:第一个网络的 UI
- javascript - 用于属性链(嵌套)的Javascript hasOwnProperty?
- corda - Corda Ledger 大小问题
- mysql - Nodejs & sequalize mysql 对数据库的查询只发生一次
- opencv - 用于从特征匹配中生成 3D 点云的管道
- sql - CSV 导出值为 000000 的 SQL 结果变为 0
- python - 如何在 Python 中读取 .doc 文件
- c# - WPF 绑定:禁用 TextBoxes + 验证和 DataContext 问题