<?php
add_action( 'vc_before_init', 'rockon_club_WITHVS' );
function rockon_club_WITHVS() {
   vc_map( array(
      "name" => __("Rockon Club Photos",'rockon'),
      "base" => "rockon_club_post",
      "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" => __("Rockon Club Photos",'rockon'),
            "description" => __("Title text Here.",'rockon')
         ),
         array(
            "type" => "dropdown",
            "holder" => "div",
            "class" => "",
            "heading" => __("Number Of Row",'rockon'),
            "param_name" => "no_of_row",
            "value" => array('1','2','3'),
            "description" => __("Choose no of row.",'rockon')
         ),
		  array(
            "type" => "dropdown",
            "holder" => "div",
            "class" => "",
            "heading" => __("Number Of Post",'rockon'),
            "param_name" => "no_of_post",
            "value" => array('4','8','12','16','20'),
            "description" => __("Choose no of post.",'rockon')
         )
      )
   ) );
}
add_shortcode( 'rockon_club_post', 'rockon_club_post_func' );
function rockon_club_post_func( $atts ) { // New function parameter $content is added!
   extract( shortcode_atts( array(
      'title' => 'something',
	  'no_of_row' => '2',
	  'no_of_post' => '8'
   ), $atts ) );
   $result = '';
   global $post;
   $result .= '<div class="rock_heading_div">
        <div class="rock_heading">
          <h1>'.__(esc_attr($title),'rockon').'</h1>
          <p>X</p>
        </div>
      </div>
      <div class="rock_club_photo">
        <div id="rock_club_photo_slider" class="owl-carousel owl-theme">';
	 $j = $i = 0;
	 $club_query = new WP_Query( array( 'post_type' => 'portfolio', 'posts_per_page' => $no_of_post) );
	 if($club_query->have_posts()): 
		while($club_query->have_posts()) : $club_query->the_post();
		 if($j == $i){
          $result .= '<div class="rock_club_photo_slider_item">';
		  $j = $j + $no_of_row;
		 }
            $result .= '<div class="rock_club_photo_item">';
				$src = '';
				if (has_post_thumbnail($post->ID))
				{	
					$thumb = get_post_thumbnail_id($post->ID);
					$thumb_w = '380';
					$thumb_h = '283';
					$src = wp_get_attachment_url($thumb, 'full');
					$image = aq_resize($src, $thumb_w, $thumb_h, true);
					$result .= '<img src="'.esc_url($image).'"  alt="">';
				}else{
					$src = ROCKON_PATH.'/images/no_image.jpg';
					$result .= '<img src="'.ROCKON_PATH.'/images/no_image.jpg" alt="">';
				}
				$result .= '<div class="rock_club_photo_overlay">
                <div class="photo_link animated fadeInDown"> <a href="'.esc_url(get_permalink($post->ID)).'"><i class="fa fa-link"></i></a> <a class="fancybox" data-fancybox-group="group1" href="'.esc_url($src).'"><i class="fa fa-search-plus"></i></a> </div>
                <a class="rock_club_photo_detail animated fadeInUp" href="'.esc_url(get_permalink($post->ID)).'">'.__(get_the_title($post->ID),'').'</a> </div>';
            $result .= '</div>';
		 if(($j-1) == $i){
          $result .= '</div>';
		 }
		 $i++;
		endwhile; 
	 endif; 
     $result .= '</div><div class="customNavigation"> <a class="rock_slider_button prev"><i class="fa fa-angle-left"></i></a> <a class="rock_slider_button next"><i class="fa fa-angle-right"></i></a> </div>
      </div>';
	
	return $result;
   
}
?>