添加html_template参数vc_row简码的可视化编辑器
问题描述:
我的代码:添加html_template参数vc_row简码的可视化编辑器
// 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()的作品,但代码的第二部分引发以下错误:
(!) Fatal error: Wrong vc_map object. Base attribute is required in /Users/mike/Sites/Fun/wordpress/web/app/plugins/js_composer/include/helpers/helpers_api.php on line 26
这些都是资源我以前看了看:
- https://stackoverflow.com/a/29226825/3602355
- http://mwender.com/adding-html-id-attributes-to-visual-composer-rows-in-the-x-theme/#comment-1170
- https://snippets.khromov.se/changing-settings-of-built-in-visual-composer-elements/#comment-22548
相关文章:
- https://wpbakery.atlassian.net/wiki/pages/viewpage.action?pageId=524332 - vc_map()
- https://wpbakery.atlassian.net/wiki/pages/viewpage.action?pageId=524310 - vc_map_update()
任何帮助将不胜感激。
答
实际上,功能vc_map_update
只返回简码的参数,但不是所有的设置。
您需要使用vc_get_shortcode
函数,它将返回整个元素。
有了:$element = vc_get_shortcode('vc_row');
另外,有没有需要更换滤芯,因为vc_map_update
显然会对其进行更新。
答
我发现了一个解决方案:
我发现我太过于复杂了。我找到了用于手动设置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'));
你能帮我什么完整的代码将是什么样子? @Павел –
@AllureWebSolutions,使用$ shortcode = vc_get_shortcode('vc_row');然后更改$ shortcode变量并使用vc_map_update('vc_row',$ shortcode); –
当我尝试我得到以下错误:'错误:错误的设置名为短代码:vc_row。基地不能修改。' –