问题描述
当然,我试图对其进行过度设计,因此这是一个简化的过程,因此一直在尝试利用此资源:https://github.com/reaktivstudios/cmb2-flexible-content
我现在正在尝试将其模块化构建到我的主题中,以便可以无缝地将其拖放到另一个网站。文件夹的结构如下:
FC-FUNCTIONS.PHP - 这是创建一个可以在页面模板上调用以启动内容创建的函数:
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','id' => $prefix . 'flexible_content','type' => 'flexible','priority' => 'high','show_names' => true,'options' => array(
'flexible_title'=> __( 'Row {#}','add_button' => __( 'Add Row','remove_button' => __( 'Remove Row','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 {#}','add_button' => __( 'Add Another Banner','remove_button' => __( 'Remove Banner','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','name' => 'Title text','id' => $prefix . 'title','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 -->';
}
我面临的主要问题是按钮不会显示给我,向上/向下箭头和中继器组“添加另一个横幅”按钮。但是,我可以查看字段、添加/删除布局、填充内容并在前端输出。
请帮助我使 Hero Banner 组字段可重复并且每个布局都可拖放。
这是正在处理的其中一个页面的后端图像,您可以看到它们不可排序,并且没有选项(在创建中指定)重复和创建多个英雄横幅相同的分组:
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)