WordPress Customizer隐藏背景图像复选框



我正在尝试将复选框添加到"显示背景图像"中。未选中时,它应该设置背景图像:无针对该元素。我看不到我要去哪里了。

这就是我在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' );
        }
    });
});

尝试从'Background_image'设置中删除默认值。

最新更新