Javascript Backstretch.js,带有来自页面ID的WordPress特色图片

Javascript Backstretch.js,带有来自页面ID的WordPress特色图片,javascript,php,wordpress,jquery-backstretch,Javascript,Php,Wordpress,Jquery Backstretch,我在一个单页网站上工作,每个部分都通过一个帖子id加载内容 <?php $id=193; $post = get_page($id); echo $post->post_content; ?> 每个页面都有自己的完整背景图像,放在content div下,我使用Backstretch.js在div id中创建该图像 示例。 在此之前,一切都很完美,但我想让背景图像可以通过WordPress中的“特色图像”选项进行编辑,而不是像现在这样硬编码,但无法找到解决方案 应该是这

我在一个单页网站上工作,每个部分都通过一个帖子id加载内容

<?php $id=193; $post = get_page($id); echo $post->post_content; ?>

每个页面都有自己的完整背景图像,放在content div下,我使用Backstretch.js在div id中创建该图像

示例。

在此之前,一切都很完美,但我想让背景图像可以通过WordPress中的“特色图像”选项进行编辑,而不是像现在这样硬编码,但无法找到解决方案

应该是这样的(我猜):

$(函数(){
$(“#pageOneImage”).backstretch(“”);
$(“#pageTwoImage”).backstretch(“”);
});

其实很简单:

<?php $thumb_id = 1; $url = wp_get_attachment_url( get_post_thumbnail_id($thumb_id) ); ?>

<script>
$("#divname").backstretch("<?php echo $url ?>");
</script>

$(“#divname”).backstretch(“”);

对我来说,这段代码很好用:

<script>
jQuery(document).ready(function($) {
     jQuery(".your-class-or-ID").backstretch("
 <?php
    $thumb_id = get_post_thumbnail_id();
    $thumb_url = wp_get_attachment_image_src($thumb_id,'full', true);                
    echo $thumb_url[0];
?>");
});
</script>

jQuery(文档).ready(函数($){
jQuery(“.your class或ID”).backstretch(“
");
});
<script>
jQuery(document).ready(function($) {
     jQuery(".your-class-or-ID").backstretch("
 <?php
    $thumb_id = get_post_thumbnail_id();
    $thumb_url = wp_get_attachment_image_src($thumb_id,'full', true);                
    echo $thumb_url[0];
?>");
});
</script>