Wordpress 嵌套项-可视化编写器
我尝试为VisualComposer versrion 5.2创建新的小部件 我找到了这个 因此,我创建了一些示例小部件:Wordpress 嵌套项-可视化编写器,wordpress,visual-composer,Wordpress,Visual Composer,我尝试为VisualComposer versrion 5.2创建新的小部件 我找到了这个 因此,我创建了一些示例小部件: <?php /* Plugin Name: Example nested item Plugin URI: http://wpbakery.com/vc Description: Version: 0.1.1 Author: PG License: GPLv2 or later */ // don't load directly if (!defined(
<?php
/*
Plugin Name: Example nested item
Plugin URI: http://wpbakery.com/vc
Description:
Version: 0.1.1
Author: PG
License: GPLv2 or later
*/
// don't load directly
if (!defined('ABSPATH')) die('-1');
class ExampleNested {
public function __construct()
{
// We safely integrate with VC with this hook
add_action('vc_before_init', [$this, 'initVC']);
// Use this when creating a shortcode addon
add_shortcode('your_gallery', [$this, 'renderGallery']);
add_shortcode('single_img', [$this, 'renderSingleImg']);
}
public function renderGallery()
{
/**
*
*/
}
public function renderSingleImg()
{
/**
*
*/
}
public function initVC() {
vc_map( array(
"name" => __("Your Gallery", "my-text-domain"),
"base" => "your_gallery",
"as_parent" => array('only' => 'single_img'), // Use only|except attributes to limit child shortcodes (separate multiple values with comma)
"content_element" => true,
"show_settings_on_create" => false,
"is_container" => true,
"params" => array(
// add params same as with any other content element
array(
"type" => "textfield",
"heading" => __("Extra class name", "my-text-domain"),
"param_name" => "el_class",
"description" => __("If you wish to style particular content element differently, then use this field to add a class name and then refer to it in your css file.", "my-text-domain")
)
),
"js_view" => 'VcColumnView'
) );
vc_map( array(
"name" => __("Gallery Image", "my-text-domain"),
"base" => "single_img",
"content_element" => true,
"as_child" => array('only' => 'your_gallery'), // Use only|except attributes to limit parent (separate multiple values with comma)
"params" => array(
// add params same as with any other content element
array(
"type" => "textfield",
"heading" => __("Extra class name", "my-text-domain"),
"param_name" => "el_class",
"description" => __("If you wish to style particular content element differently, then use this field to add a class name and then refer to it in your css file.", "my-text-domain")
)
)
) );
}
}
new ExampleNested();
//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 {
}
}
VC中嵌套元素的示例
vc_map(array(
"name" => __("Slideshow", "my-text-domain"),
"base" => "slideshow_content",
"as_parent" => array('only' => 'slideshow_item_content'),
"content_element" => true,
"show_settings_on_create" => false,
"is_container" => true,
"js_view" => 'VcColumnView',
'icon' => get_template_directory_uri() . '/vc-elements/img/slideshow.png',
"category" => array('my-text-domain Elements', 'Content'),
"params" => array(
array(
"type" => "textfield",
"heading" => __("Class", "my-text-domain"),
"param_name" => "slider_class"
),
),)); if (!function_exists('slideshow_content')) {
function slideshow_content($atts, $content = null)
{
extract(shortcode_atts(array(
'slider_class' => '',
), $atts));
$output =' output goes here';
return $output;
}
add_shortcode('slideshow_content', 'slideshow_content'); } vc_map(array(
"name" => __("Slider Item", "my-text-domain"),
"base" => "slideshow_item_content",
"content_element" => true,
"as_child" => array('only' => 'slideshow_content'),
"show_settings_on_create" => true,
'icon' => get_template_directory_uri() . '/vc-elements/img/slideshow-add.png',
"params" => array(
array(
"type" => "textfield",
"heading" => __("Title", "my-text-domain"),
"param_name" => "title"
),
array(
'type' => 'attach_image',
'heading' => __('Add Image', 'my-text-domain'),
'param_name' => 'item_img',
),
), )); if (!function_exists('slideshow_item_content')) {
function slideshow_item_content($atts, $content = null)
{
extract(shortcode_atts(array(
'title' => '',
'item_img' => '',
), $atts));
$image = wp_get_attachment_image_src($item_img, 'full');
$image_src = $image['0'];
$output = '<li><img src="'.$image_src.'" alt=""></li>';
return $output;
}
add_shortcode('slideshow_item_content', 'slideshow_item_content'); } if (class_exists('WPBakeryShortCodesContainer')) {
class WPBakeryShortCode_slideshow_content extends WPBakeryShortCodesContainer
{
}} if (class_exists('WPBakeryShortCode')) {
class WPBakeryShortCode_slideshow_item_content extends WPBakeryShortCode
{
} }
vc_映射(数组)(
“名称”=>“(“幻灯片放映”、“我的文本域”),
“基本”=>“幻灯片内容”,
“作为父项”=>array('仅'=>'幻灯片放映项目内容'),
“内容元素”=>true,
“在创建时显示设置”=>false,
“is_container”=>true,
“js_视图”=>“VcColumnView”,
'icon'=>get_template_directory_uri()。/vc elements/img/slideshow.png',
“category”=>array('my-text-domain元素','Content'),
“params”=>数组(
排列(
“键入”=>“文本字段”,
“标题”=>““类”、“我的文本域”),
“参数名称”=>“滑块类”
),
),)); 如果(!函数_存在('slideshow_content')){
函数幻灯片内容($atts,$content=null)
{
提取(短码)附件(数组)(
'滑块类'=>'',
)美元(附件);;
$output='output goes here';
返回$output;
}
添加_shortcode('slideshow_content','slideshow_content');}vc_映射(数组(
“名称”=>“(“滑块项”、“我的文本域”),
“基本”=>“幻灯片放映项目内容”,
“内容元素”=>true,
“作为子项”=>array('仅'=>'幻灯片内容'),
“在创建时显示设置”=>true,
'icon'=>get_template_directory_uri()。/vc elements/img/slideshow add.png',
“params”=>数组(
排列(
“键入”=>“文本字段”,
“标题”=>“(“标题”、“我的文本域”),
“参数名称”=>“标题”
),
排列(
'类型'=>'附加图像',
'heading'=>''Add Image','my text domain'),
'参数名称'=>'项目名称',
),
), )); 如果(!function_存在('slideshow_item_content')){
函数幻灯片内容($atts,$content=null)
{
提取(短码)附件(数组)(
'标题'=>'',
'item_img'=>'',
)美元(附件);;
$image=wp_get_attachment_image_src($item_img,'full');
$image_src=$image['0'];
$output='';
返回$output;
}
如果(class_存在('wpbakeryshortcodecontainer'),则添加_短代码('slideshow_item_content','slideshow_item_content');}{
WPBakeryShortCode类\u幻灯片放映\u内容扩展了WPBakeryShortCodeContainer
{
}}如果(类_存在('WPBakeryShortCode')){
WPBakeryShortCode类\u幻灯片放映\u项目\u内容扩展了WPBakeryShortCode
{
} }