带有 do_action 短代码的 Visual Composer Grid 不起作用 [英] Visual Composer Grid with do_action shortcode is not working
问题描述
我有一个充满整个主题的视觉作曲家.当我在编辑器的页面中添加以下网格短代码时,它可以正常工作.
[vc_basic_grid post_type="post_type" max_items="10" item="masonryGrid_SlideFromLeft" grid_id="vc_gid:1458178666639-80ebf3775500c87d35de078c3422fe96-10" 分类单元"5"5"
但是,当我使用 do_action 调用完全相同的代码时,会出现以下 javascript 错误.我检查了 html 输出,使用 do_action 也是一样的,就像将短代码放在编辑器中一样.
<块引用>错误:语法错误,无法识别的表达式:{'status':'Nothing found'}秒
非常感谢任何帮助.
好吧,你不能像那样使用 VC 的核心短代码直接在模板中输出内容.
1.问题:
为了安全,除了 nonce,VC 使用 page_id
和 shortcode_id
来检查 AJAX 请求/响应数据.
shortcode_id
是VC自动生成的,不能硬编码.
例如,这是您在管理编辑器屏幕上看到的短代码:
[vc_basic_grid post_type=post_type";max_items=10"item="masonryGrid_SlideFromLeft";grid_id=vc_gid:1458178666639-80ebf3775500c87d35de078c3422fe96-10"分类法=555"]
假设页面 ID 为 4269,这是前端生成的 HTML 代码:
<div class="vc_grid-container-wrapper vc_clearfix"><div class="vc_grid-container vc_clearfix wpb_content_element vc_masonry_grid";数据初始加载动画=放大"data-vc-grid-settings="{"page_id":4269,"style":"all-masonry","action":"vc_get_vc_grid_data","shortcode_id":"1458178678c304030666-10","tag":"vc_masonry_grid"}"data-vc-request=http://example.com/wp-admin/admin-ajax.php";data-vc-post-id=4269";data-vc-public-nonce=0641473b09">
<!-- vc_grid 结束-->
现在,如果 page_id
和 shortcode_id
不匹配,{'status':'Nothing found - $shorcode_id'}
将被丢弃,不会显示任何内容.
您可以在 vc_grid.min.js
文件中找到更多信息.
2.解决方案:
- 使用 VC 生成一个假页面,然后将生成的 html 代码复制到您的模板文件中.
- 直接用VC创建模板.立>
- 使用 Shorcode Mapper 创建您自己的代码.
I have visual composer which is packed with total theme. When I put the following grid short code in my page in the editor it works correctly.
[vc_basic_grid post_type="post_type" max_items="10" item="masonryGrid_SlideFromLeft" grid_id="vc_gid:1458178666639-80ebf3775500c87d35de078c3422fe96-10" taxonomies="555"]
However, when I call the exact same code using do_action it gives the following javascript error. I checked the html output and it is the same using do_action like putting the short code in editor.
Error: Syntax error, unrecognized expression: {'status':'Nothing found'} s
Any help is greatly appreciated.
Well, you can't output contents directly in your templates by using core shortcodes of VC like that.
1. Problem:
For security, besides nonce, VC uses page_id
and shortcode_id
to check AJAX request/respond data.
The shortcode_id
is automatically generated by VC, you can not harcode it.
For example, this is the shortcode you see on admin editor screen:
[vc_basic_grid post_type="post_type" max_items="10" item="masonryGrid_SlideFromLeft" grid_id="vc_gid:1458178666639-80ebf3775500c87d35de078c3422fe96-10" taxonomies="555"]
Let say the page ID is 4269, this is the generated HTML code on front-end:
<!-- vc_grid start -->
<div class="vc_grid-container-wrapper vc_clearfix">
<div class="vc_grid-container vc_clearfix wpb_content_element vc_masonry_grid" data-initial-loading-animation="zoomIn" data-vc-grid-settings="{"page_id":4269,"style":"all-masonry","action":"vc_get_vc_grid_data","shortcode_id":"1458178666639-80ebf3775500c87d35de078c3422fe96-10","tag":"vc_masonry_grid"}" data-vc-request="http://example.com/wp-admin/admin-ajax.php" data-vc-post-id="4269" data-vc-public-nonce="0641473b09">
</div>
</div>
<!-- vc_grid end -->
Now, if page_id
and shortcode_id
don't match each other, {'status':'Nothing found - $shorcode_id'}
will be throw out and no contents will be displayed.
You can find out more inside vc_grid.min.js
file.
2. Solution:
- Generate a fake page with VC, then copy generated html code to your template file.
- Create a template with VC directly.
- Use Shorcode Mapper to create your own shorcode.
这篇关于带有 do_action 短代码的 Visual Composer Grid 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!