Class 9

I’ve Registered a Post type for “Testimonial’ then made a shortcode where user can query a post by ‘Post type’,  ‘Item’, for post limit ‘Order’, for Ascending or Descending and so all. Finally I made a Visual Composer addon where user can handle all those features dynamically.

[php]

<?php
//registering post type
function seo_testimonial_custompost(){
register_post_type(‘testimonial’, array(
‘labels’ => array(
‘name’ => ‘Testimonial’,
‘add_new’ => ‘Add new Testimonial’
),
‘public’ => true,
‘supports’ => array(‘title’, ‘thumbnail’)
));
}
add_action(‘init’, ‘seo_testimonial_custompost’);

//shortcode
function seo_testimonial_shortcode($atts, $content = null){
extract(shortcode_atts(
array(
‘type’ => ‘post’,
‘item’ => 5,
‘order’ => ‘ASC’,
‘color’ => ‘color’,
‘icon’ => ‘icon’
), $atts
));

$q = new WP_Query(array(
‘post_type’ => $type,
‘posts_per_page’ => $item,
‘order’ => $order
));

$list = ‘<ul>’;
while($q->have_posts()) : $q->the_post();
$list .= ‘<li>’;
if(!empty($icon)){
$list .= ‘<i class="’.$icon.’"></i> ‘;
}
$list .= ‘<a href="’.get_permalink().’" style="color:’.$color.’">’.get_the_title().'</a></li>’;
endwhile;
$list .= ‘</ul>’;

return $list;
}
add_shortcode(‘post_list’, ‘seo_testimonial_shortcode’);

function seo_post_item_show(){
vc_map(array(
‘name’ => ‘Post Title’,
‘base’ => ‘post_list’,
‘category’ => ‘SEO’,
‘params’ => array(
array(
‘type’ => ‘textfield’,
‘heading’ => ‘Post Type’,
‘description’ => ‘Put post type here’,
‘value’ => ‘post’,
‘param_name’ => ‘type’
),
array(
‘type’ => ‘textfield’,
‘heading’ => ‘Post Item’,
‘description’ => ‘Put your item number’,
‘value’ => 1,
‘param_name’ => ‘item’
),
array(
‘type’ => ‘textfield’,
‘heading’ => ‘Post Order’,
‘description’ => ‘Put Post order’,
‘value’ => ‘ASC’,
‘param_name’ => ‘order’
),
array(
‘type’ => ‘colorpicker’,
‘heading’ => ‘Post Color’,
‘description’ => ‘Select post color’,
‘value’ => ‘#333333’,
‘param_name’ => ‘color’
),
array(
‘type’ => ‘iconpicker’,
‘heading’ => ‘Post Icon’,
‘description’ => ‘Select post Icon’,
‘value’ => ‘fa fa-leaf’,
‘param_name’ => ‘icon’
)
)
));
}
add_action(‘vc_before_init’, ‘seo_post_item_show’);
?>

[/php]

Leave a Reply

Your email address will not be published. Required fields are marked *