

<?php    $count = 1; 
$query_args = array('post_type' => 'sh_portfolio' , 'showposts' => $num , 'order_by' => $sort , 'order' => $order);

if( $cat ) $query_args['portfolio_category'] = $cat;
$query = new WP_Query($query_args) ;  

$filteration = array();

ob_start();
			
			if($query->have_posts()):

				while($query->have_posts()): $query->the_post(); 

					$meta = _WSH()->get_meta();
					$terms = wp_get_post_terms(get_the_id(), 'portfolio_category');
					$post_terms = array();
					if($terms) foreach ($terms as $key => $value) {
						$filteration[$value->term_id] = '
							<li class="wow fadeInLeft"  data-wow-delay="0.2s">
								<a data-filter=".'.esc_attr($value->slug).'" href="#">'.$value->name.'</a>
							</li>';
						$post_terms[] = $value->slug;
					} ?>

					<div class="portfolio-item <?php if($post_terms) echo implode(' ', $post_terms) ?>">
						<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
							<?php the_post_thumbnail('900x900'); ?>
							<div class="caption">
								<div class="tb">
									<div class="tb-cell">

										<div>
											<span class="icon"><i class="fa fa-plus"></i></span>
											<span data-mfp-src="<?php echo esc_url(wp_get_attachment_url(get_post_thumbnail_id())); ?>" class="icon lightbox"><i class="fa fa-search"></i></span>
										</div>
										
										<h3 class="uppercase"><?php the_title(); ?></h3>
										<em><?php echo balanceTags(implode(' / ', (array)wp_get_post_terms(get_the_id(), 'portfolio_category', array('fields'=>'names')))) ?></em>

									</div> <!-- / .tb-cell -->
								</div> <!-- / .tb -->
							</div>  <!-- / .caption -->
						</a>
					</div> <!-- / .portfolio-item -->
				
				<?php endwhile; ?>
			
			<?php endif; ?>
			
<?php $data = ob_get_clean();
wp_reset_postdata(); 

ob_start();?>

			<div class="padding-top">
				<div class="container">

					<header class="header-section wow fadeInDown" data-wow-duration="1.5s">
						<h2><?php echo balanceTags($title); ?></h2>
						<p><?php echo balanceTags($text); ?></p>
					</header> <!-- / .header-section -->


					<div class="portfolio-filters">
						<ul>
							<li class="wow fadeInLeft"  data-wow-delay="0s">
								<a data-filter="*" href="#"><?php esc_html_e('all', SH_NAME); ?></a>
							</li>
							
							<?php if( $filteration ) echo balanceTags(implode(" ", $filteration)); ?>

						</ul>
					</div> <!-- / .portfolio-filter -->

				</div> <!-- / .container -->

				<div class="portfolio-container">
					<?php echo balanceTags($data); ?>
				</div>  <!-- / .portfolio-container -->
			</div>
<?php return ob_get_clean(); ?>