<?php 
	$dem = 1;
	if ( have_posts() ) : while ( have_posts() ) : the_post();
		
		$post_id  = (int)get_post_thumbnail_id( );
		$port_img = wp_get_attachment_image_src( $post_id, 'large' )[0];
		$type 	  = get_post_meta( $post->ID, "ainex_portfolio_type", true );
		switch ($type) {
			case 'image':
				$port_link  = get_post_meta( $post->ID, "ainex_portfolio_image", true );
				$clas_audio = '';
			break;
			
			case 'slider':
				$clas_audio = '';
				$port_link  = $port_img;
			break;
			
			case 'video':
				$port_link  = get_post_meta( $post->ID, "ainex_portfolio_video", true );
				$clas_audio = '';
			break;

			case 'soundcloud':
				$link_audio = get_post_meta( $post->ID, "ainex_portfolio_soundcloud", true );
				$clas_audio = ' fancybox.iframe';
				$port_link  = 'http://w.soundcloud.com/player/?url='. $link_audio .'&show_artwork=true';
			break;

			default:
				$port_link  = $port_img;
				$clas_audio = '';
			break;
		}

		$taxonomy = 'dslc_projects_cats';
		$post_id  = (int)get_the_id();

		$post_terms = wp_get_object_terms( $post_id, $taxonomy, array( 'fields' => 'ids' ) );

		if ( !empty( $post_terms ) && !is_wp_error( $post_terms ) ) {
		$term_ids = implode( ',' , $post_terms );

		$args = array(
		  	'orderby'                  => 'name',
		  	'order'                    => 'ASC',
		  	'include'                  => $term_ids,
		  	'taxonomy'                 => $taxonomy,
		);

		$categories = get_categories( $args );
		$cats_slug  = array();
			foreach ( $categories as $category ) {
			  $cats_slug[] = $category->slug;
			}
		}

	?>
		<div class="<?php echo implode(" ", $cats_slug); ?>">
            <a class="fancybox fancybox-media<?php echo $clas_audio; ?>" href="<?php echo $port_link; ?>" data-fancybox-group="gallery" title="<?php the_title( ); ?>">
		        <div class="imgWrap">
		        	<img src="<?php echo $port_img; ?>" alt="" />
		        	<p class="imgDescription"><i class="icon-search icon-4x"></i></p>
		        	<h3><?php the_title( ); ?></h3>
		        </div>
            </a>
        </div>
<?php
	$dem++;
	endwhile;	
	else : 

		/**
		 * Display no posts message if none are found.
		 */
		get_template_part('loop/content','none');

	endif;