我创建了数量可变的字段,用于将图像添加到nivoslider。它工作得很好,但我必须手动刷新整个页面,并从customizer面板中重新选择部分,以使更改生效。我想知道是否有任何方法可以让定制器面板本身通过php代码刷新,而不仅仅是实时网站区域。
这是代码
$wp_customize->add_section(\'slider_section\',array(
\'title\' => esc_html__(\'Slider Settings\',\'customslide\'),
\'description\' => esc_html__(\'Add slider images here.\',\'customslide\'),
\'priority\' => null
));
$wp_customize->add_setting(\'num_of_slides\'.$i,array(
\'default\' => esc_html__(\'2\',\'customslide\'),
\'transport\' => \'refresh\',
\'sanitize_callback\' => \'absint\',
));
$wp_customize->add_control(\'num_of_slides\',array(
\'label\' => esc_html__(\'Number of Slides\',\'customslide\'),
\'section\' => \'slider_section\',
\'type\' => \'text\'
));
$num_of_slides_value = esc_html(get_theme_mod(\'num_of_slides\',\'2\'));
for ($i=1; $i<$num_of_slides_value+1; $i++) {
// Slide Image i
$wp_customize->add_setting(\'slide_image\'.$i,array(
\'default\' => get_template_directory_uri().\'/images/slides/slider\'.$i.\'.jpg\',
\'sanitize_callback\' => \'esc_url_raw\',
));
$wp_customize->add_control(
new WP_Customize_Image_Control(
$wp_customize,
\'slide_image\'.$i,
array(
\'label\' => esc_html__(\'Slide Image \'.$i.\' (1440x700)\',\'customslide\'),
\'section\' => \'slider_section\',
\'settings\' => \'slide_image\'.$i
)
)
);
$wp_customize->add_setting(\'slide_title\'.$i,array(
\'default\' => esc_html__(\'Responsive Design\',\'customslide\'),
\'sanitize_callback\' => \'sanitize_text_field\',
));
$wp_customize->add_control(\'slide_title\'.$i,array(
\'label\' => esc_html__(\'Slide Title \'.$i,\'customslide\'),
\'section\' => \'slider_section\',
\'type\' => \'text\'
));
$wp_customize->add_setting(\'slide_desc\'.$i,array(
\'default\' => esc_html__(\'This is description for slider one.\',\'customslide\'),
\'sanitize_callback\' => \'customslide_format_for_editor\',
));
$wp_customize->add_control(\'slide_desc\'.$i,array(
\'label\' => esc_html__(\'Slide Description \'.$i,\'customslide\'),
\'section\' => \'slider_section\',
\'setting\' => \'slide_desc\'.$i,
\'type\' => \'textarea\'
));
$wp_customize->add_setting(\'slide_link\'.$i,array(
\'default\' => \'#link\'.$i,
\'sanitize_callback\' => \'esc_url_raw\',
));
$wp_customize->add_control(\'slide_link\'.$i,array(
\'label\' => esc_html__(\'Slide Link \'.$i,\'customslide\'),
\'section\' => \'slider_section\',
\'type\' => \'text\'
));
}