我尝试在自定义程序中添加一个复选框以显示背景图像"。如果未选中,则应将background-image:none设置为该元素。我无法看到我出错的地方。
这就是我在customizer.php文件中的内容
// Background Image
$wp_customize->add_setting( 'background_image', array(
'default' => get_template_directory_uri() . '/images/default.jpg',
'transport' => 'postMessage'
) );
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'background_image', array(
'label' => __( 'Background Image', 'minitheme' ),
'settings' => 'background_image'
) ) );
// Display Background Image
$wp_customize->add_setting( 'display_background_image', array(
'default' => true,
'transport' => 'postMessage'
) );
$wp_customize->add_control( 'display_background_image', array(
'label' => __( 'Display Background Image', 'minitheme' ),
'type' => 'checkbox'
) );
...
public static function header_output() {
?>
<!--Customizer CSS-->
<style type="text/css">
<?php self::generate_css( '#header', 'background-image', 'slide_1_background_image' ); ?>
#slide-1 {display: <?php
$display = get_theme_mod('display_slide_1_background_image', '1');
if ('false') {echo 'none';}
?>; }
</style>
<!--/Customizer CSS-->
<?php
}
这是我在相应的customizer.js文件中的代码:
// Background Image
wp.customize( 'background_image', function( value ) {
value.bind( function( newval ) {
$('#slide-1').css('background-image', 'url("' + newval + '")' );
} );
} );
// Display Background Image
wp.customize( 'display_background_image', function( value ) {
value.bind( function( to ) {
if ( false === to ) {
$( '#header' ).css('background-image', 'none' );
}
});
});
答案 0 :(得分:0)
尝试从&#39; background_image&#39;中删除默认值设置。