Visual Composer 在容器中嵌套短代码

问题描述 投票:0回答:3

我刚刚使用 vc_map 为 WordPress 网站创建了一个嵌套短代码。

效果很好,而且非常简单。

我的父母简码是“simple_table”,我的孩子简码是“simple_table_row”。

[simple_table param="foo"]
   [simple_tablerow param="another_foo"]
   [simple_tablerow param="another_foo"]
   [simple_tablerow param="another_foo"]
[/simple_table]

我可以在页面根部或行中添加我的短代码。

但是,我无法添加另一个容器,如选项卡、游览、手风琴或可分页容器。我的嵌套短代码没有出现在元素列表中。我已经创建了几个简单的短代码,它们在这些特定情况下可以正常工作。

这是我的 vc_map :

vc_map( array(
    "name" => "Simple_table",
    "description" => "Simple_table",
    "base" => "simple_table",
    "class" => "simple_table",
    "content_element" => true,
    "is_container" => true,
    'as_parent' => array('only' => 'simple_tablerow'),
    "show_settings_on_create" => true,
    "icon" => "simple_table_icon", 
    "category" => __('Content', 'js_composer'),
    "js_view" => 'VcColumnView',
    "params" => array(
                    array(
                        'type' => 'param_group',
                        'value' => '',
                        'param_name' => 'cols',
                        "heading" => "Cols",
                        'params' => array(
                            array(
                                'type' => 'textfield',
                                "holder" => "div",
                                'value' => '',
                                'heading' => 'Data',
                                'param_name' => 'data',
                                'admin_label' => true,
                            ),
                            array(
                                'type' => 'textfield',
                                'value' => '',
                                'heading' => 'Style',
                                'param_name' => 'style',
                            ),
                            array(
                                'type' => 'textfield',
                                'value' => '',
                                'heading' => 'Class',
                                'param_name' => 'class',
                            )
                        )
                    ),
                    array(
                      "type" => "checkbox",
                      "class" => "",
                      "heading" => "hide_header",
                      "param_name" => "hide_header"
                  ),
                    array(
                         "type" => "textfield",
                         "holder" => "",
                         "class" => "",
                         "heading" => "Class",
                         "param_name" => "class"
                    ),
      ),
    )
);

vc_map( array(
    "name" => "Simple_tablerow",
    "description" => "simple_tablerow",
    "base" => "simple_tablerow",
    "class" => "simple_tablerow",
    "content_element" => true,
    "as_child" =>  array('only' => 'simple_table'),
    "show_settings_on_create" => true,
    "icon" => "hide_header",
    "category" => __('Content', 'js_composer'),
    "params" => array(
        array(
            'type' => 'param_group',
            'value' => '',
            'param_name' => 'cols',
            "heading" => "Cols",
            'params' => array(
                array(
                    'type' => 'textfield',
                    'value' => '',
                    'heading' => 'Data',
                    'param_name' => 'data',
                    'admin_label' => true,
                ),
                array(
                    'type' => 'textfield',
                    'value' => '',
                    'heading' => 'Style',
                    'param_name' => 'style',
                ),
                array(
                    'type' => 'textfield',
                    'value' => '',
                    'heading' => 'Class',
                    'param_name' => 'class',
                )
            ),
        ),
        array(
            'type' => 'textfield',
            'value' => '',
            'heading' => 'Class',
            'param_name' => 'class',
        )
    ),
    )
);

如何添加选项卡、游览、手风琴或可分页容器等容器中可用的嵌套短代码?

注意:参数“allowed_container_element”似乎是原因,但如何修改这个值?

wordpress visual-composer
3个回答
2
投票

希望您已经找到了答案,因为这有点旧了,但我自己正在寻找答案,并且出现了这个问题。

此文档网站可能对您有用https://kb.wpbakery.com/docs/developers-how-tos/nested-shortcodes-container/

如果我不得不猜测,您似乎忘记了底部扩展

WPBakeryShortCodesContainer

的最后一段代码
//Your "container" content element should extend WPBakeryShortCodesContainer class to inherit all required functionality
if ( class_exists( 'WPBakeryShortCodesContainer' ) ) {
  class WPBakeryShortCode_Your_Gallery extends WPBakeryShortCodesContainer {
  }
}
if ( class_exists( 'WPBakeryShortCode' ) ) {
  class WPBakeryShortCode_Single_Img extends WPBakeryShortCode {
  }
}

0
投票

距最初的问题已经过去了 3 年多,但我也遇到了类似的问题。删除以下行对我有用:

"is_container" => true,

0
投票

这是老问题,但这是我找到的解决方案。这是在内列中添加容器元素的示例,您也可以为其他元素进行修改。

add_filter( 'vc_element_settings_filter', 'inner_column_settings_filter', 10, 2 );
function inner_column_settings_filter( $settings, $tag ) {
    
    if ( $tag == 'vc_column_inner' ) {
        $settings['allowed_container_element'] = true;
    }

    return $settings;
}
© www.soinside.com 2019 - 2024. All rights reserved.