【问题标题】:Adding html_template parameter to vc_row shortcode in Visual Composer在 Visual Composer 中将 html_template 参数添加到 vc_row 短代码
【发布时间】:2017-04-19 00:02:05
【问题描述】:

我的代码:

    // Add language dropdown to visual composer settings
    if (function_exists('vc_add_param')) {
        vc_add_param('vc_row', array(
            'type' => 'dropdown',
            'heading' => "Language",
            'param_name' => 'language',
            'value' => array("English", "Russian"),
            'description' => __("Select Language", "discprofile"),
            'weight' => 1, //  default 0 (unsorted, appened to bottom, 1- append to top)
        ));
    }

    // Set custom html_template to display data-lang attribute
    if (function_exists('vc_map')) {

        // setup custom attributes
        $attributes = array(
            'html_template' => 'vc_templates/vc_row.php'
        );

        // Update 'vc_row' to include custom vc_row template and remap shortcode
        $params = vc_map_update('vc_row', $attributes);

        // Remove default vc_row
        vc_remove_element('vc_row');

        // Remap shortcode with custom template
        vc_map($params['vc_row']);
    }

vc_add_param() 可以工作,但是代码的第二部分抛出以下错误:

( ! ) 致命错误:错误的 vc_map 对象。在第 26 行的 /Users/mike/Sites/Fun/wordpress/web/app/plugins/js_composer/include/helpers/helpers_api.php 中需要基本属性

这些是我之前看过的资源:

相关文档:

任何帮助将不胜感激。

【问题讨论】:

    标签: php wordpress visual-composer


    【解决方案1】:

    我找到了解决办法:

    我发现我过于复杂了。我找到了手动设置 vc_templates 目录的 Visual Composer 方法。无需更新短代码 html_template 参数,也无需映射新的短代码。

    这将代码简化为以下内容:

    // Set custom html_template to display data-lang attribute
    $dir = __DIR__ . '/vc_templates';
    vc_set_shortcodes_templates_dir( $dir );
    var_dump( vc_shortcodes_theme_templates_dir( 'vc_row.php' ) );
    

    【讨论】:

      【解决方案2】:

      实际上,vc_map_update 函数只返回简码参数,而不是所有设置。

      您需要使用vc_get_shortcode 函数来返回整个元素。

      与:$element = vc_get_shortcode('vc_row');

      另外,没有必要替换元素,因为vc_map_update 显然会更新它。

      【讨论】:

      • 你能帮我看看完整代码的样子吗? @Павел
      • @AllureWebSolutions,使用 $shortcode = vc_get_shortcode('vc_row');然后更改 $shortcode 变量并使用 vc_map_update('vc_row',$shortcode);
      • 当我尝试我得到以下错误:Error: Wrong setting_name for shortcode:vc_row. Base can't be modified.
      • 我想出了一个替代解决方案。感谢您的帮助!
      • @AllureWebSolutions,您可以向我们展示您的解决方案,以供未来的发现者使用。顺便说一句,你也可以在 vc_map_update 之前使用unset($shortcode['base']);
      猜你喜欢
      • 2018-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-14
      • 2017-03-30
      • 1970-01-01
      • 2018-02-18
      • 1970-01-01
      相关资源
      最近更新 更多