php - 如何在wordpress的背景图像中使用帖子缩略图网址?
问题描述
我正在使用这段代码。
<div class="bg-img1 size-a-3 how1 pos-relative" style="background-image: url();">
这时候如何获取背景图片中的post thumbnail url?
解决方案
代码应如下所示,
<div class="bg-img1 size-a-3 how1 pos-relative" style="background-image: url(<?php the_post_thumbnail_url(); ?>);">
如果您想使用帖子 ID 从特定帖子/页面获取帖子缩略图,则如下所示,
<div class="bg-img1 size-a-3 how1 pos-relative" style="background-image: url(<?php echo get_the_post_thumbnail_url($post_id); ?>);">
推荐阅读
- reactjs - 无效的挂钩调用。使用 useDispatch 时,只能在函数组件的主体内部调用 Hooks
- vb.net - 如何将日期时间转换为秒 vb.net
- angular - 如何将 api 返回的数据转换为 Angular 中的 json?
- r - 如何在条形图中的误差条和条形之间进行颜色叠加?
- dictionary - 将地图的条目分组到列表中
- laravel - Laravel 8:为了让 SPA 永远不会出现 419 错误,使用 Sanctum 并将路由放在 api 路由中是否合适?
- php - 教义:将枚举类定义为实体的columDefinition
- flutter - 颤振升级不适用于提供不正确网址的 vs 代码?
- java - OpenUI/Swagger java 到 API
- r - 如何分配R中色带上显示的最大值