假设您有一个数组$locations
可用时,可以使用此代码在自定义程序中生成下拉列表。它与单个值没有什么不同。
$section_name = \'wpse213980_section_name\'; // adapt to your naming system
$section_title = \'wpse213980_section_title\'; // adapt to your naming system
$setting_name = \'wpse213980_setting_name\'; // adapt to your naming system
$setting_field_type = \'select\';
$setting_field_options = $locations;
$sanitize_callback = \'sanitize_text_field\';
$wp_customize->add_setting($setting_name, array(
\'default\' => \'\',
\'type\' => \'theme_mod\',
\'capability\' => \'edit_theme_options\',
\'theme_supports\' => \'\',
\'transport\' => \'refresh\',
\'sanitize_callback\' => $sanitize_callback
));
$control_args = array(
\'section\' => $section_name,
\'label\' => $setting_title,
\'settings\' => $setting_name,
\'priority\' => 10,
\'type\' => $setting_field_type,
\'choices\' => $setting_field_options,
);
$wp_customize->add_control( new WP_Customize_Control ($wp_customize, $setting_name, $control_args));
道具
Otto.