wordpress - 如何为用户未设置的帖子设置缩略图
问题描述
如果用户在创建帖子时没有选择缩略图,我希望主题为帖子设置缩略图。
我尝试浏览 WordPress 法典,但我可以找到任何“设置方法”。
<div class="standard-featured">
<?php if( has_post_thumbnail() ) { ?>
<?php the_post_thumbnail(); ?>
<?php } else { ?>
<img src="//Set your image default Path here.">
<?php } ?>
</div>
解决方案
有很多方法可以做到这一点。这是一种更清洁的方法。下面的代码示例。
<?php if( has_post_thumbnail() ) : ?>
<?php the_post_thumbnail() ?>
<?php else : ?>
// Dafult thumbnail image for post. try to write the exact image location.
<img src="default.jpg" />
<?php endif; ?>
推荐阅读
- sql - DistinctRow 返回重复行 (MS-Access SQL)
- android-studio - 当我创建第二个空活动时,出现了一个浮动按钮,所以你能告诉我如何在 android studio 3.1.3 中删除浮动按钮
- postgresql - Pg 锁 - 数千行的 transactionid 和 pid 为空
- angular - 如何保留存储在 Angular 2 中给定服务实例的引用变量中的值?
- google-chrome-extension - 边缘扩展不响应 runtime.onMessage.addListener()
- django - 安装 django-leaflet 以匹配 django 版本
- python - 在python中循环文件
- php - 如何在 PHP 中从 YouTube 数据 API 访问统计信息
- sql - PostgreSQL:创建临时表,添加到主选择查询并避免多行错误
- r - ggplot2中geom_bar图上的错误边框颜色