对不起,我的英语。我试图在Customizer中实现一个图像选择器,以便在首页上选择和显示css背景图像。php。基础it在前端按预期工作。但是我无法在customizer中运行预览。更改的图像仅在F5刷新后显示。
我所做的:函数。php
$wp_customize->add_setting(\'startGalleryImg1\', array(
\'default\' => get_stylesheet_directory_uri() . \'/images/assets/default.jpg\',
\'transport\' => \'postMessage\',
\'sanitize_callback\' => \'esc_url_raw\',
));
$wp_customize->add_control(
new WP_Customize_Image_Control(
$wp_customize,
\'startGalleryImg1\',
array(
\'label\' => __( \'1st Start Gallery Img\', \'theme_name\' ),
\'description\' => __( \'Choose first Start Gallery Img\', \'theme_name\' ),
\'section\' => \'bloook_theme_section\',
\'settings\' => \'startGalleryImg1\',
)
)
)
我的模板:
<a class="item item1" href="#">
<div class="item-bg" style="background-image: url(\'<?php echo get_theme_mod(\'startGalleryImg1\') ?>\')">
</div>
<div class="item-content">
<h3>Demos</h3>
<p>Web, Video, Musik</p>
</div>
我的自定义程序。js(适用于其他字段(textarea…)
(function ($) {
wp.customize(\'startGalleryImg1\', function (value) {
value.bind(function (to) {
$(\'.home .item1 .item-bg\').css(\'background-image\', \'url( \'+ to +\')\');
});
});
})(jQuery);
我想知道是否有专家可以帮助我。非常感谢并致以亲切的问候