php - 如何从 wordpress 帖子中提取图像以将其显示在屏幕上?
问题描述
我正在尝试为我的帖子显示类似缩略图的内容。有没有可以做到这一点的wordpress功能?我阅读了有关 wordpress 特色图片的信息,但我没有看到在 wordpress 管理页面上设置一个的选项。
我也尝试过使用the_post_thumbnail()
,但没有用。
这就是我的 div 目前的样子:
<div class="card" style="width: 22rem;">
<img src="<?php the_post_thumbnail(); ?>" class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title"><?php the_title() ?></h5>
<p class="card-text">Random Card content</p>
</div>
</div>
解决方案
只需使用:
<?php the_post_thumbnail(); ?>
像下面的代码:
<div class="card" style="width: 22rem;">
<?php the_post_thumbnail('post-thumbnail', ['class' => 'card-img-top']);?>
<div class="card-body">
<h5 class="card-title"><?php the_title(); ?></h5>
<p class="card-text">Random Card content</p>
</div>
</div>
使用时the_post_thumbnail()
不要使用额外的img
标签!
推荐阅读
- ios - 使用 Swift 4.2 将图库中的图片上传到 Firebase
- javascript - 自动计算 valueAxix min
- abap - 类型池或常量类?
- javascript - 反应组件未显示
- rest - 缺少父级的 Spring-rest 子资源请求
- ruby - 为什么 `gem install` 和 `add_runtime_dependency` 安装不同的版本?
- git - 使用 git 进行多平台统一的游戏开发
- vue.js - 如何在 vue-select 的一个函数中使用元素/选项的串联名称
- amazon-mws - 亚马逊 MWS,返回的 Feed 提交 ID 不是唯一的
- postgresql - 如何使用 SQL 上另一个查询的数据进行查询?