AFAIK在customizer_register
挂钩状态。因此,这个问题可能有不同的原因,但从您的问题中看,它们并不明显。此外,我不确定你想要实现什么,所以你可能想根据@Rarst的问题来填补信息空白。除此之外,还有多种方法,例如,向定制器添加一个分类下拉列表,我选择了一个并链接了另一个,请参见下文。
<小时/>Disclaimer:
这不是我的代码,出于完整性原因,我将其添加到此处,并添加了指向源代码的链接。我自己还没有试过,但据我所知,它没有任何问题,而且对人们有用。
主题定制器的分类代码下拉列表→ Source 根据要点→ 根据博客article 作者:Eric Juden
这将进入functions.php
add_action(\'customize_register\', \'my_customize_register\');
function my_customize_register($wp_customize){
require_once(TEMPLATEPATH . \'/class/wp_customizer_taxonomy_dropdown.php\');
$wp_customize->add_section(\'my_theme_blog_featured_categories\', array(
\'title\' => __(\'Blog: Featured Categories\'),
\'priority\' => 36,
));
$wp_customize->add_setting(\'featured_category_1\', array(
\'default\' => get_option(\'default_category\', \'\'),
));
$wp_customize->add_control( new Taxonomy_Dropdown_Customize_Control($wp_customize, \'featured_category_1\', array(
\'label\' => __(\'Featured Area 1\'),
\'section\' => \'my_theme_blog_featured_categories\',
\'settings\' => \'featured_category_1\',
\'args\' => array(), // arguments for wp_dropdown_categories function...optional. array(\'taxonomy\' => \'my_taxonomy\')
)));
return $wp_customize;
}
该文件名为
wp_customizer_taxonomy_dropdown.php
位于相对于功能的文件夹中。php,称为
class
:
class Taxonomy_Dropdown_Customize_Control extends WP_Customize_Control {
public $type = \'taxonomy_dropdown\';
var $defaults = array();
public $args = array();
public function render_content(){
// Call wp_dropdown_cats to ad data-customize-setting-link to select tag
add_action(\'wp_dropdown_cats\', array($this, \'wp_dropdown_cats\'));
// Set some defaults for our control
$this->defaults = array(
\'show_option_none\' => __(\'None\'),
\'orderby\' => \'name\',
\'hide_empty\' => 0,
\'id\' => $this->id,
\'selected\' => $this->value(),
);
// Parse defaults against what the user submitted
$r = wp_parse_args($this->args, $this->defaults);
?>
<label><span class="customize-control-title"><?php echo esc_html($this->label); ?></span></label>
<?php
// Generate our select box
wp_dropdown_categories($r);
}
function wp_dropdown_cats($output){
// Search for <select and replace it with <select data-customize=setting-link="my_control_id"
$output = str_replace(\'<select\', \'<select \' . $this->get_link(), $output);
return $output;
}
}
这应该与附加信息相联系,并能自我解释。
其他类似方法
→
WordPress Theme Customizer Custom Controls 作者@bueltge
→ 链接到
source 分类学下拉列表示例的Gist
→ 他的
answer 关于这个话题
→ 还有一些教程、文章等,如果需要的话,您可以自己轻松找到。