在CMB元数据库上添加选项卡


add tabs on CMB Metaboxes

我目前正在使用Github上的CMB元盒作为我的主题-https://github.com/WebDevStudios/CMB2-我的问题是,这个插件能支持除了单一标准wordpress部分之外的垂直选项卡吗。我想添加多个字段或内容组,而不会让用户感到沮丧或困惑。如果没有,我谦虚地问你是否可以帮我简单解释一下(可能是编码结构),我可以自己添加标签作为这个插件的挂钩。

感谢您提前提供的帮助。

问候,

最近,我们的团队创建了一个扩展来解决这个问题:GitHub

使用示例:

add_filter( 'cmb2_init', 'example_tabs_metaboxes' );
function example_tabs_metaboxes() {
$box_options = array(
    'id'           => 'example_tabs_metaboxes',
    'title'        => __( 'Example tabs', 'cmb2' ),
    'object_types' => array( 'page' ),
    'show_names'   => true,
);
// Setup meta box
$cmb = new_cmb2_box( $box_options );
// setting tabs
$tabs_setting           = array(
    'args' => $box_options,
    'tabs' => array()
);
$tabs_setting['tabs'][] = array(
    'id'     => 'header',
    'title'  => __( 'Header', 'cmb2' ),
    'fields' => array(
        array(
            'name' => __( 'Title', 'cmb2' ),
            'id'   => 'header_title',
            'type' => 'text'
        ),
        array(
            'name' => __( 'Subtitle', 'cmb2' ),
            'id'   => 'header_subtitle',
            'type' => 'text'
        ),
        array(
            'name'    => __( 'Background image', 'cmb2' ),
            'id'      => 'header_background',
            'type'    => 'file',
            'options' => array(
                'url' => false
            )
        )
    )
);
$tabs_setting['tabs'][] = array(
    'id'     => 'platforms',
    'title'  => __( 'Platforms', 'cmb2' ),
    'fields' => array(
        array(
            'name' => __( 'Title', 'cmb2' ),
            'id'   => 'platforms_title',
            'type' => 'text'
        ),
        array(
            'name' => __( 'Subtitle', 'cmb2' ),
            'id'   => 'platforms_subtitle',
            'type' => 'text'
        ),
        array(
            'id'      => 'platforms',
            'type'    => 'group',
            'options' => array(
                'group_title'   => __( 'Platform {#}', 'cmb2' ),
                'add_button'    => __( 'Add platform', 'cmb2' ),
                'remove_button' => __( 'Remove platform', 'cmb2' ),
                'sortable'      => false
            ),
            'fields'  => array(
                array(
                    'name' => __( 'Title', 'cmb2' ),
                    'id'   => 'title',
                    'type' => 'text'
                ),
                array(
                    'name' => __( 'Description', 'cmb2' ),
                    'id'   => 'description',
                    'type' => 'textarea'
                ),
                array(
                    'name'       => __( 'Link', 'cmb2' ),
                    'id'         => 'link',
                    'type'       => 'text_url',
                    'attributes' => array(
                        'placeholder' => 'http://'
                    )
                ),
                array(
                    'name'    => __( 'Background image', 'cmb2' ),
                    'id'      => 'background',
                    'type'    => 'file',
                    'options' => array(
                        'url' => false
                    )
                )
            )
        )
    )
);
$tabs_setting['tabs'][] = array(
    'id'     => 'reviews',
    'title'  => __( 'Reviews', 'cmb2' ),
    'fields' => array(
        array(
            'name' => __( 'Title', 'cmb2' ),
            'id'   => 'review_title',
            'type' => 'text'
        ),
        array(
            'name' => __( 'Subtitle', 'cmb2' ),
            'id'   => 'review_subtitle',
            'type' => 'text'
        ),
        array(
            'id'      => 'reviews',
            'type'    => 'group',
            'options' => array(
                'group_title'   => __( 'Review {#}', 'cmb2' ),
                'add_button'    => __( 'Add review', 'cmb2' ),
                'remove_button' => __( 'Remove review', 'cmb2' ),
                'sortable'      => false
            ),
            'fields'  => array(
                array(
                    'name' => __( 'Author name', 'cmb2' ),
                    'id'   => 'name',
                    'type' => 'text'
                ),
                array(
                    'name'    => __( 'Author avatar', 'cmb2' ),
                    'id'      => 'avatar',
                    'type'    => 'file',
                    'options' => array(
                        'url' => false
                    )
                ),
                array(
                    'name' => __( 'Comment', 'cmb2' ),
                    'id'   => 'comment',
                    'type' => 'textarea'
                )
            )
        )
    )
);
// set tabs
$cmb->add_field( array(
    'id'   => 'tabs__',
    'type' => 'tabs',
    'tabs' => $tabs_setting
) );
}