您可以使用custom control 通过重写render_content()
, eg公司
add_action( \'customize_register\', function ( $wp_customize ) {
// Custom control.
class PPL_Ninja_Skin_Select_Customize_Control extends WP_Customize_Control {
public $type = \'select\';
// Override to inject our javascript.
public function render_content() {
parent::render_content();
?>
<script type="text/javascript">
(function () {
var skin_select = $(\'#customize-control-ppl-ninja-theme-options-skin\').find(\'select\');
var custom_group = [
\'#accordion-section-custom_header_styles\',
\'#accordion-section-custom_slider_styles\',
\'#accordion-section-custom_footer_styles\',
\'#accordion-section-custom_general_colors\'
];
skin_select.change(function () {
if ($(this).val() == 4) {
$(custom_group.join(\',\')).hide();
} else {
$(custom_group.join(\',\')).show();
}
});
skin_select.change();
}());
</script>
<?php
}
}
$wp_customize->add_setting( \'ppl-ninja-theme-options-skin\' );
$wp_customize->add_section( \'ppl-ninja-theme-options\', array(
\'title\' => __( \'Ninja Options\', \'ppl\' ),
) );
// Add custom control.
$wp_customize->add_control( new PPL_Ninja_Skin_Select_Customize_Control(
$wp_customize, \'ppl-ninja-theme-options-skin\', array(
\'label\' => __( \'Skin\', \'ppl\' ),
\'section\' => \'ppl-ninja-theme-options\',
\'choices\' => array(
\'\' => __( \'Select\', \'ppl\' ),
1 => __( \'One\', \'ppl\' ),
2 => __( \'Two\', \'ppl\' ),
3 => __( \'Three\', \'ppl\' ),
4 => __( \'Four\', \'ppl\' ),
),
)
) );
// Test data.
foreach ( array( \'header_styles\', \'slider_styles\', \'footer_styles\', \'general_colors\' ) as $setting ) {
$wp_customize->add_setting( \'custom_\' . $setting . \'-setting\' );
$wp_customize->add_section( \'custom_\' . $setting, array(
\'title\' => sprintf( __( \'Ninja %s\', \'ppl\' ), $setting ),
) );
$wp_customize->add_control( \'custom_\' . $setting . \'-setting\', array (
\'label\' => __( \'Setting\', \'td\' ),
\'section\' => \'custom_\' . $setting,
) );
}
} );
(也不用担心任何CSS)。