I am trying to make a slider configurable via the customizer. In order to let the user decide how many sliders he wants, I added a setting where the user can enter a number.
Based on this number I want to generate sections, settings, and controls in the customizer, under my slider panel.
The function that is building the sections looks like this:
function createSliders($array) {
foreach($array as $id) {
$wp_customize->add_section(
'slider_'.$id,
array(
'title' => __( 'Slider '.$slider, 'Kraftzwerg' ),
'capability' => 'edit_theme_options',
'panel' => 'slider'
)
);
$i++;
}
$array
only holds the identifier (0-max) for the slider.
If I start the customizer I get an instant 500 error.
I know that I can't see the sections because there are no settings and controls for the section. But I didn't get over the 500 error.
Can someone tell me why it won't run?
I am trying to make a slider configurable via the customizer. In order to let the user decide how many sliders he wants, I added a setting where the user can enter a number.
Based on this number I want to generate sections, settings, and controls in the customizer, under my slider panel.
The function that is building the sections looks like this:
function createSliders($array) {
foreach($array as $id) {
$wp_customize->add_section(
'slider_'.$id,
array(
'title' => __( 'Slider '.$slider, 'Kraftzwerg' ),
'capability' => 'edit_theme_options',
'panel' => 'slider'
)
);
$i++;
}
$array
only holds the identifier (0-max) for the slider.
If I start the customizer I get an instant 500 error.
I know that I can't see the sections because there are no settings and controls for the section. But I didn't get over the 500 error.
Can someone tell me why it won't run?
I suppose you didn't pass $wp_customize
properly. I'd do this:
section_number
which determine user's choicecustomizer.php
customizer.php
add_action('customize_register', 'my_customizer');
function my_customizer($wp_customize){
$section_number = get_theme_mod('section_number', 0);
for($i = 0; $i <= $section_number; $i++) {
$wp_customize->add_section(
'slider_'.$i,
array(
'title' => __( 'Slider '.$slider, 'Kraftzwerg' ),
'capability' => 'edit_theme_options',
'panel' => 'slider'
)
);
}
Should work. Note that your sections won't appear if you won't attach any setting to it