在我的主题中,我使用Theme Customization API设置了两个选项,下面是代码片段。
我想在radio
为真,checkbox
为假,checkbox
隐藏时显示radio
选项。我尝试使用active_callback
,但没有工作。那么,如何实现这个功能呢?
谢谢!
// Related Post.
$wp_customize->add_setting('_related_post', array(
'capability' => 'edit_theme_options',
'default' => 0,
'transport' => 'postMessage',
));
$wp_customize->add_control('_related_post', array(
'settings' => '_related_post',
'label' => __('Display Related Posts', 'typenow'),
'section' => '_theme_options',
'type' => 'checkbox',
'priority' => 30,
));
// Related Post Num.
$wp_customize->add_setting('_related_post_num', array(
'capability' => 'edit_theme_options',
'default' => '2',
'transport' => 'postMessage',
));
$wp_customize->add_control('_related_post_num', array(
'settings' => '_related_post_num',
'label' => __('Related Posts Number', 'typenow'),
'section' => '_theme_options',
'type' => 'radio',
'priority' => 35,
'choices' => array (
'2' => __('Two posts', 'typenow'),
'4' => __('Four posts', 'typenow'),
),
));
答案 0 :(得分:0)
解决方案:
$wp_customize->add_control('_related_post_num', array(
'settings' => '_related_post_num',
'label' => __('Related Posts Number', 'typenow'),
'section' => '_theme_options',
'type' => 'radio',
'priority' => 35,
'choices' => array (
'2' => __('Two posts', 'typenow'),
'4' => __('Four posts', 'typenow'),
),
'active_callback' => function(){
return get_theme_mod( '_related_post', false );
},
));