我通常用JavaScript编写,但是我目前正在尝试为辅助项目设置Wordpress主题。我发现了一些资源,概述了如何通过内联样式将设置的特色图像用作div背景图像,但是它们有些陈旧。我目前正在尝试找到的basic method,并尝试对其进行更新以匹配当前的Wordpress Docs,但是我对PhP还是陌生的。
在我的功能文件中,我有:
add_theme_support( 'post-thumbnails' );
在我的模板文件中,我有:
<?php $bgImg = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'large'); ?>
<section style="background: url('<?php echo $bgImg[0]; ?>') no-repeat;">
</section>
该部分正在渲染,但开发工具显示“背景:url((未知))”
答案 0 :(得分:0)
我使用类似的方法:
$thumb_id = get_post_thumbnail_id();
$thumb_url_array = wp_get_attachment_image_src($thumb_id, 'thumbnail-size', true);
$thumb_url = $thumb_url_array[0];
<div class="image row" style="background: url('<? echo $thumb_url; ?>'); ">content</div
编辑: 这是默认情况下的图像尺寸列表。 https://codex.wordpress.org/Post_Thumbnails#Thumbnail_Sizes
答案 1 :(得分:0)
使用以下代码代替您的代码。
var mongoose = require('mongoose');
Schema = mongoose.Schema;
var MongooseSchema = new Schema({
emailServer : [{
email : {type:String}
}]
},{ collection: "RegisteredUserDetails" })
module.exports = mongoose.model('MongooseSchema',MongooseSchema)