Php 如何让WordPress live customizer选择通过Ajax自动更新的选项?
如果我想在我的WordPress主题定制器中对不同的选项使用选择选项,我如何选择在主题上进行实时更改 因此,我的functions.php文件中有这样一个部分:Php 如何让WordPress live customizer选择通过Ajax自动更新的选项?,php,jquery,arrays,ajax,wordpress,Php,Jquery,Arrays,Ajax,Wordpress,如果我想在我的WordPress主题定制器中对不同的选项使用选择选项,我如何选择在主题上进行实时更改 因此,我的functions.php文件中有这样一个部分: $wp_customize->add_setting( 'menu_type', array( 'transport' => 'postMessage', 'default' => 'choice1', ) ); $wp_customize->add_co
$wp_customize->add_setting(
'menu_type',
array(
'transport' => 'postMessage',
'default' => 'choice1',
)
);
$wp_customize->add_control(
'menu_type',
array(
'type' => 'select',
'label' => 'Select your menu type:',
'section' => 'header_section',
'choices' => array(
'choice1' => 'Choice 1',
'choice2' => 'Choice 2',
'choice3' => 'Choice 3',
'choice4' => 'Choice 4',
),
)
);
wp.customize( 'menu_type', function( value ) {
value.bind( function( newval ) {
$('.someclass').css('border', '1px solid #111');
} );
} );
在我的ajax文件中,我有这样一个部分:
$wp_customize->add_setting(
'menu_type',
array(
'transport' => 'postMessage',
'default' => 'choice1',
)
);
$wp_customize->add_control(
'menu_type',
array(
'type' => 'select',
'label' => 'Select your menu type:',
'section' => 'header_section',
'choices' => array(
'choice1' => 'Choice 1',
'choice2' => 'Choice 2',
'choice3' => 'Choice 3',
'choice4' => 'Choice 4',
),
)
);
wp.customize( 'menu_type', function( value ) {
value.bind( function( newval ) {
$('.someclass').css('border', '1px solid #111');
} );
} );
ajax文件中的代码将css更改为所有选项。那么,我需要在我的ajax文件中添加什么,这样我就只能对“choice1”进行更改了?好的,下面是答案:
wp.customize( 'menu_type', function( value ) {
value.bind( function( newval ) {
if ( newval == 'choice1' ) {
$( '.someclass' ).css('border', '1px solid #111');
} else if ( newval == 'choice2' ) {
$( '.someclass' ).css('border', '1px solid #222');
} else if ( newval == 'choice3' ) {
$( '.someclass' ).css('border', '1px solid #333');
}
} );
} );