个性化阅读
专注于IT技术分析

WordPress:如何在定制程序中使用活动回调

在我的主题中, 我设置了两个使用主题自定义API的选项, 下面是代码片段。

我想在复选框为true时显示单选选项, 在复选框为false时隐藏单选。我尝试使用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'), ), ));

#1


解决方案:

$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 );
    }, ));
赞(0)
未经允许不得转载:srcmini » WordPress:如何在定制程序中使用活动回调

评论 抢沙发

评论前必须登录!