Created
November 9, 2016 14:06
-
-
Save hasanm95/572ed4c4660b05ad05f5296310da598a to your computer and use it in GitHub Desktop.
Create visual composer with param_group
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Backend visual composer add-on code | |
vc_map(array( | |
'name' => 'Accordions', | |
'base' => 'maxima_accordion', | |
'category' => 'Maxima', | |
'params' => array( | |
array( | |
'type' => 'textfield', | |
'name' => __('Title', 'rrf-maxima'), | |
'holder' => 'div', | |
'heading' => __('Title', 'rrf-maxima'), | |
'param_name' => 'title', | |
), | |
array( | |
'type' => 'param_group', | |
'param_name' => 'values', | |
'params' => array( | |
array( | |
'type' => 'textfield', | |
'name' => 'label', | |
'heading' => __('Heading', 'rrf-maxima'), | |
'param_name' => 'label', | |
), | |
array( | |
'type' => 'textarea', | |
'name' => 'Content', | |
'heading' => __('Content', 'rrf-maxima'), | |
'param_name' => 'excerpt', | |
) | |
) | |
), | |
), | |
)); | |
//shortcode | |
function maxima_accordion_shortcode($atts){ | |
extract(shortcode_atts(array( | |
'title' => '', | |
'values' => '', | |
), $atts)); | |
$list = '<h4>'.$title.'</h4>'; | |
$values = vc_param_group_parse_atts($atts['values']); | |
$new_accordion_value = array(); | |
foreach($values as $data){ | |
$new_line = $data; | |
$new_line['label'] = isset($new_line['label']) ? $new_line['label'] : ''; | |
$new_line['excerpt'] = isset($new_line['excerpt']) ? $new_line['excerpt'] : ''; | |
$new_accordion_value[] = $new_line; | |
} | |
$idd = 0; | |
foreach($new_accordion_value as $accordion): | |
$idd++; | |
$list .= | |
'<div class="panel panel-default"> | |
<div class="panel-heading"> | |
<h4 class="panel-title"> | |
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapse'.$idd.'"> | |
'.$accordion['label'].' | |
<span class="fa fa-plus"></span> | |
</a> | |
</h4> | |
</div> | |
<div id="collapse'.$idd.'" class="panel-collapse collapse"> | |
<div class="panel-body"> | |
<p>'.$accordion['excerpt'].'</p> | |
</div> | |
</div> | |
</div>'; | |
endforeach; | |
return $list; | |
wp_reset_query(); | |
} | |
add_shortcode('maxima_accordion', 'maxima_accordion_shortcode'); | |
Is htere a way to pass values to label and excerpt on start for multiple fields? So to have multiple fields visible on start with predefined values?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@rozuja Don't think you need any more, but it might help someone in the future:
You can get the values by calling
vc_param_group_parse_atts([the param_group])
function.for example if you have a
param_group
with param_nametitles
, use: