在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
) );
}
相关文章:
- 如何为下拉列表的每个选项添加一个属性
- 使用jQuery向“选择选项”添加默认属性
- 将默认选项添加到ng-if
- 从jquery中的select选项添加两个不同的数组值(text&value)
- 为selectize.js选项添加数据属性
- 将select选项添加到id中
- AngularJS ng选项添加了另一个选项
- 将选项添加到插件msDropdown生成的下拉列表的最佳方式是什么
- 将选项添加到多选并设置为选定
- 如何将空白选项添加到木偶收藏视图生成的选择中
- 如何将此选项添加到此图像选取器项目中
- 使用 XHR 更新服务器文件并将选项添加到 html 选择
- 如何使用 JavaScript 将选项添加到 HTML 表单下拉列表中
- 为什么当我将数据选项添加到骨干模型获取时,它不会触发回调
- 如何将下拉列表中的所有选项添加到 php 中的数组中
- 角度JS多选选项添加额外的?选择
- 自动选择<选项>添加到<选择>
- 如何动态地将所选选项添加到表中
- 动态地将选项添加到 Angular 选定的组合框中
- AngularJS:将选项添加到选择而不选择它