因此,这里似乎有两个问题:首先,您似乎没有建立像下面这样的WP\\u Customize\\u控件的新实例,而且重要的是要记住,您必须至少为设置和控件提供最小数组项,否则它将不会显示,您在设置中有一个空数组。
您还想确保您的命名约定不是以数字开始的,所以我在下面将它们切换了。
以下是您可以尝试的代码更改:
add_action(\'customize_register\', \'homepage_sections\');
//products
function homepage_sections($wp_customize){
$wp_customize->add_panel(
\'homepage_sections\',
array(
\'title\' => \'Homepage Sections\',
\'priority\' => \'20\'
)
);
$wp_customize->add_section(
\'homepage_settings_section\',
array(
\'title\' => \'Homepage settings\',
\'panel\' => \'homepage_sections\',
)
);
$wp_customize->add_setting(
\'homepage_settings_setting\',
array(
\'default\' => 1
)
);
$wp_customize->add_control(
new WP_Customize_Control(
\'homepage_settings_control\',
array(
\'section\' => \'homepage_settings_section\',
\'settings\' => \'homepage_settings_setting\',
\'label\' => \'Number of sections\',
\'description\' => \'Number of sections in homepage\',
\'type\' => \'number\'
)
)
);
global $wpdb;
$sections=$wpdb->get_results(\'SELECT section_id, section_title FROM vt_homepage_sections;\');
foreach($sections as $key) :
$section_id=$key->section_id;
$cust_setting_id = \'setting_\' . $section_id;
$cust_control_id = \'control_\' . $section_id;
$wp_customize->add_setting(
$cust_setting_id,
array(
\'default\' => \'\',
\'transport\' => \'refresh\',
)
);
$wp_customize->add_control(
new WP_Customize_Control(
$cust_control_id,
array(
\'settings\' => $cust_setting_id,
\'section\' => \'homepage_settings_section\',
\'label\' => \'test Control\'
)
)
);
endforeach;
}