<?php 
wp_enqueue_script('jquery-mixitup');
tycheproperty_bunch_global_variable();
$paged = get_query_var('paged');
$args = array('post_type' => 'bunch_gallery', 'showposts'=>"-1", 'orderby'=>$sort, 'order'=>$order, 'paged'=>$paged);
$terms_array = explode(",",$exclude_cats);
if($exclude_cats) $args['tax_query'] = array(array('taxonomy' => 'gallery_category','field' => 'id','terms' => $terms_array,'operator' => 'NOT IN',));
$query = new WP_Query($args);
//query_posts($args);
//wp_enqueue_script( array( 'jquery-prettyphoto', 'cubeportfolio', 'main-script','jquery-isotope','portfolio' ) );
$t = $GLOBALS['_bunch_base'];
$paged = get_query_var('paged');
$data_filtration = '';
$data_posts = '';
?>
<?php if( $query->have_posts() ):
	
ob_start();?>
	<?php $count = 0; 
	$fliteration = array();?>
	<?php while( $query->have_posts() ): $query->the_post();
		global  $post;
		$meta = get_post_meta( get_the_id(), '_bunch_portfolio_meta', true );//printr($meta);
		$meta1 = _WSH()->get_meta();
		$post_terms = get_the_terms( get_the_id(), 'gallery_category');// printr($post_terms); exit();
		foreach( (array)$post_terms as $pos_term ) $fliteration[$pos_term->term_id] = $pos_term;
		$temp_category = get_the_term_list(get_the_id(), 'gallery_category', '', ', ');
	?>
		<?php $post_terms = wp_get_post_terms( get_the_id(), 'gallery_category'); 
		$term_slug = '';
		if( $post_terms ) foreach( $post_terms as $p_term ) $term_slug .= $p_term->slug.' ';?>		
           <?php 
			$post_thumbnail_id = get_post_thumbnail_id($post->ID);
			$post_thumbnail_url = wp_get_attachment_url( $post_thumbnail_id );
		   ?>
           <!--Default Portfolio Item-->
            <div class="default-portfolio-item masonry-item all <?php echo esc_attr($term_slug); ?> <?php if(tycheproperty_set($meta1, 'extra_width') == 'extra_width') echo 'col-md-8 col-sm-6 col-xs-12'; else echo 'col-md-4 col-sm-6 col-xs-12'?>">
                <div class="inner-box">
                    <figure class="image-box">
                        <?php if(tycheproperty_set($meta1, 'extra_width') == 'extra_width') 
                            $image_size = 'tycheproperty_770x500'; 
                            else
                            $image_size = 'tycheproperty_370x235'; 
                            the_post_thumbnail($image_size);
                        ?>
                    </figure>
                    <!--Overlay Box-->
                    <div class="overlay-box">
                        <div class="overlay-inner">
                            <div class="content">
                                <h3><a href="<?php echo esc_url(get_permalink(get_the_id()));?>" title=""><?php the_title();?></a></h3>
                            </div>
                        </div>
                    </div>
                    <!--Gallery Popup Button-->
                    <a href="<?php echo esc_url($post_thumbnail_url);?>" class="image-link lightbox-image" title=""><span class="icon fa fa-compress"></span></a>
                </div>
            </div>
            
<?php endwhile;?>
  
<?php wp_reset_postdata();
$data_posts = ob_get_contents();
ob_end_clean();
endif; 
ob_start();?>	 
<?php $terms = get_terms(array('gallery_category')); ?>

<!--Gallery Section-->
<section class="gallery-section bg-lightgrey">
    <div class="auto-container">
        
        <!--Section Title-->
        <div class="sec-title text-center">
            <div class="subtitle-text"><?php echo balanceTags($upper_title);?></div>
            <h2><strong><?php echo balanceTags($strong_title);?></strong> <?php echo balanceTags($title);?></h2>
        </div>
        
        <!--Sortable Masonry-->
        <div class="sortable-masonry mixed-gallery-section">
            
            <!--Filter-->
            <div class="filters text-center">
                <ul class="filter-tabs filter-btns clearfix">
                    <li class="active filter" data-role="button" data-filter=".all"><span class="txt"><?php esc_html_e('All', 'tycheproperty');?></span></li>
                    <?php foreach( $fliteration as $t ): ?>
                    <li class="filter" data-role="button" data-filter=".<?php echo esc_attr(tycheproperty_set( $t, 'slug' )); ?>"><span class="txt"><?php echo balanceTags(tycheproperty_set( $t, 'name')); ?></span></li>
                    <?php endforeach;?>
                </ul>
            </div>
                
            
            <div class="items-container clearfix">
                <?php echo balanceTags($data_posts); ?>
            </div>
            
        </div><!--End Sortable Masonry-->
    	<?php if(($btn_link) || ($btn_text)):?>
    	<div class="load-more-outer padd-top-30 text-center"><a href="<?php echo esc_url($btn_link);?>" class="theme-btn btn-style-three"><?php echo balanceTags($btn_text);?></a></div>
    	<?php endif;?>
    </div>
    
</section>

<?php $output = ob_get_contents();
ob_end_clean(); 
return $output;?>