Php CMB2灵活的内容字段控件不起作用。帮助我创建一个可重复的组并添加拖放控件
我的任务是建立一个站点,CMB2管理自定义字段 当然,我试图对其进行过度设计,因此这是一个简化的过程,因此我一直在尝试利用这一资源: 我已经安装了CMB2 WordPress插件 我已经提取、上传并启用了上面指定的CMB2扩展插件 我现在正试图将它模块化地构建到我的主题中,这样它就可以无缝地拖放到另一个网站上。以下是文件夹的结构: 现在,我将向您展示这些文件的内容以及它们的连接方式 FC-FUNCTIONS.PHP-这是创建一个可以在页面模板上调用以启动内容创建的函数:Php CMB2灵活的内容字段控件不起作用。帮助我创建一个可重复的组并添加拖放控件,php,wordpress,custom-fields,cmb2,Php,Wordpress,Custom Fields,Cmb2,我的任务是建立一个站点,CMB2管理自定义字段 当然,我试图对其进行过度设计,因此这是一个简化的过程,因此我一直在尝试利用这一资源: 我已经安装了CMB2 WordPress插件 我已经提取、上传并启用了上面指定的CMB2扩展插件 我现在正试图将它模块化地构建到我的主题中,这样它就可以无缝地拖放到另一个网站上。以下是文件夹的结构: 现在,我将向您展示这些文件的内容以及它们的连接方式 FC-FUNCTIONS.PHP-这是创建一个可以在页面模板上调用以启动内容创建的函数: function fl
function flexible_content() {
require_once(get_stylesheet_directory().'/modules/flexible-content/flexible-content.php');
}
LAYOUTS.PHP-此文件将包含按布局分组的所有字段组:
add_action( 'cmb2_admin_init', 'fc_register_flexible_content_cmb2_field' );
function fc_register_flexible_content_cmb2_field() {
$prefix = '_fc_';
// Basic CMB2 Metabox declaration
$cmb = new_cmb2_box(
array(
'id' => $prefix . 'flexible_content_types',
'title' => __( 'Flexible Content Types' ),
'object_types' => array( 'page', ),
)
);
// Then add your flexible field definition. Each layout group should be defined in the layouts array, with the `ID` for that group as its key. Each layout group can contain a `title` and a list of CMB2 `fields`.
$cmb->add_field(
array(
'name' => __( 'Flexible Content', 'flexible_content' ),
'desc' => __( 'Add flexible content layouts', 'flexible_content' ),
'id' => $prefix . 'flexible_content',
'type' => 'flexible',
'priority' => 'high',
'show_names' => true,
'options' => array(
'flexible_title'=> __( 'Row {#}', 'flexible_content' ),
'add_button' => __( 'Add Row', 'flexible_content' ),
'remove_button' => __( 'Remove Row', 'flexible_content' ),
'sortable' => true,
),
'layouts' => array(
'hero_banner' => array(
'title' => 'Hero Banners',
'type' => 'group',
'description' => __( 'Add slides into the hero banner', 'hero_banners' ),
'repeatable' => true,
'options' => array(
'group_title' => __( 'Banners {#}', 'hero_banners' ),
'add_button' => __( 'Add Another Banner', 'hero_banners' ),
'remove_button' => __( 'Remove Banner', 'hero_banners' ),
'sortable' => true,
),
'fields' => array(
array(
'type' => 'text',
'name' => 'Heading',
'desc' => 'Hero Slide Title',
'id' => 'heading'
),
array(
'type' => 'textarea',
'name' => 'Subheading',
'desc' => 'Hero Slide Subheading Textarea',
'id' => 'subheading'
),
array(
'type' => 'text',
'name' => 'Hero Slide Link Text',
'id' => 'link_text'
),
array(
'type' => 'text_url',
'name' => 'Hero Slide Link URL',
'id' => 'link_url'
)
)
),
'fc_free_text' => array(
'title' => 'Text Group',
'fields' => array(
array(
'type' => 'text',
'name' => 'Title text',
'id' => $prefix . 'title',
),
array(
'type' => 'textarea',
'name' => 'Description textarea',
'id' => $prefix . 'description',
)
)
),
)
)
);
}
FLEXIBLE-CONTENT.PHP-这决定了在WordPress页面后端填充的layouts.PHP中为每个选定和填充的字段声明获取哪个布局
$prefix = '_fc_';
$flexible_fields = get_post_meta( get_the_ID(), $prefix . 'flexible_content', true );
if ($flexible_fields != '') {
echo '<div class="fc-content">';
foreach( $flexible_fields as $field ) {
if ( 'fc_free_text' === $field['layout'] ) {
// Free Text
require('layouts/inc/templates/fc-free-text.php');
}
}
echo '</div><!-- fc-content -->';
}
$prefix=''fc';
$flexible\u fields=get\u post\u meta(get\u ID(),$prefix.'flexible\u content',true);
如果($flexible_字段!=''){
回声';
foreach($字段作为$字段){
如果('fc_free_text'==$field['layout']){
//自由文本
要求('layouts/inc/templates/fc free text.php');
}
}
回声';
}
我面临的主要问题是按钮不会为我显示,向上/向下箭头和中继器组“添加另一个横幅”按钮。然而,我能够看到字段、添加/删除布局、填充内容并在前端输出
请帮助我使英雄旗帜组字段可重复,每个布局可拖放
这是正在处理的其中一个页面的后端图像,您可以看到它们不可排序,并且没有选项(在创建中指定)在同一分组下重复和创建多个英雄横幅: