<?php
add_action( 'vc_before_init', 'rockon_about_WITHVS' );
function rockon_about_WITHVS() {
   vc_map( array(
      "name" => __("rockon about post",'rockon'),
      "base" => "rockonaboutpost",
      "class" => "",
      "category" => __('Content','rockon'),
      'admin_enqueue_js' => array(get_template_directory_uri().'/vc_extend/bartag.js'),
      'admin_enqueue_css' => array(get_template_directory_uri().'/vc_extend/bartag.css'),
      "params" => array(
         array(
            "type" => "textfield",
            "holder" => "div",
            "class" => "",
            "heading" => __("Title",'rockon'),
            "param_name" => "title",
            "value" => __("What we Offers",'rockon'),
            "description" => __("Title text Here.",'rockon')
         ),
		 array(
            "type" => "textarea_html",
            "holder" => "div",
            "class" => "",
            "heading" => __("Description",'rockon'),
            "param_name" => "description",
            "value" => __("Lorem ipsum dolor sit amet, consectetur adipiscing elit. In ut semper erat. In sagittis vulputate nisi, a tristique massa porttitor ac. Phasellus nisi magna, feugiat at orci in, laoreet sagittis purus. Donec eu bibendum ipsum. Quisque vulputate imperdiet dignissim. Sed venenatis dui vel sollicitudin tincidunt.",'rockon'),
            "description" => __("Title text Here.",'rockon')
         ),
         array(
            "type" => "dropdown",
            "holder" => "div",
            "class" => "",
            "heading" => __("Number Of Post",'rockon'),
            "param_name" => "no_of_post",
            "value" => array('2','4','6','8','10'),
            "description" => __("choose No of Post.",'rockon')
         ),
		 array(
            "type" => "dropdown",
            "holder" => "div",
            "class" => "",
            "heading" => __("Post Type",'rockon'),
            "param_name" => "post_type",
            "value" => array('null'=>'select','services'=>'Services','club'=>'Club','disc_jockey_team'=>'Disc Jockey Team','post'=>'Post'),
            "description" => __("choose No of Post.",'rockon')
         )
      )
   ) );
}
add_shortcode( 'rockonaboutpost', 'rockonaboutpost_func' );
function rockonaboutpost_func( $atts ) { // New function parameter $content is added!
   extract( shortcode_atts( array(
      'title' => 'something',
	  'description' => '',
	  'no_of_post' => '3',
	  'post_type' => 'null'
   ), $atts ) );
   $result = '';
   $result .= '<div class="row">
    <div class="col-lg-12 col-md-12 col-sm-12 rock_what_we_offer">
      <div class="rock_heading_div">
        <div class="rock_heading">
          <h1>'.__(esc_attr($title),'rockon').'</h1>
          <p>X</p>
        </div>
      </div>
      <div class="clearfix"></div>
      <p>'.__(esc_attr($description),'rockon').'</p>
    </div>
  </div>';
  global $post;
  $i = 0;
  if($post_type != 'null'){
  $query = new WP_Query( array( 'post_type' => $post_type, 'posts_per_page' => $no_of_post) );
	if($query->have_posts()):
		while($query->have_posts()) : $query->the_post();
			if($i%2==0){
				$result .= '<div class="row">';
			}
			$result .= '<div class="col-lg-6 col-md-6 col-sm-6">
			  <div class="rock_about_offer">';
				$image = get_the_post_thumbnail( $post->ID, 'rockon-small-very-size' );
				if (has_post_thumbnail($post->ID) && !empty($image))
				{	
					$result .= $image;
				}else{
					$svg = get_post_meta( $post->ID, 'rockon_svgiconcode', true );
					if(!empty($svg)){
						$result .= '<div class="rock_service_icon">'.$svg.'</div>';
					}
				}
			   $result .= '<a href="">
				<h3>'.__(get_the_title($post->ID),'rockon').'</h3>
				</a>
				<p>'.__(get_excerpt(150)).'</p>
			  </div>
			</div>';
			if($i%2!=0){
				$result .= '</div>';
			}
			$i++;
			$image = '';
		endwhile; 
	endif; 
	}
	return $result;
   
}
?>