dongwenyou4298 2017-10-30 13:20
浏览 81
已采纳

WordPress:如何在Customizer中使用活动回调

In my theme, I set up 2 options use Theme Customization API, the code snippet below.

I want to display the radio option when the checkbox is true, when the checkbox is false, the radio hidden. I try to use active_callback,but not working. So, How can achieve this function?

Thanks!

    // 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'),
                            ),
    ));

</div>
  • 写回答

1条回答 默认 最新

  • druybew06513 2017-10-31 06:27
    关注

    The solution:

    $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 );
        },
    ));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)