繁体   English   中英

WordPress定制程序隐藏背景图像复选框

[英]WordPress Customizer Hide Background Image Checkbox

我正在尝试向自定义程序添加一个复选框以“显示背景图像”。 如果未选中,则应将background-image:none设置为该元素。 我看不到我要去哪里错了。

这就是我的customr.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
}

这是我相应的customr.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”设置中删除默认值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM