<?php get_header(); ?>

<?php 
$term = get_term_by('slug', get_query_var( 'term' ), get_query_var( 'taxonomy' )); 

$kk_content_style = get_theme_mod( 'kktfwp_content_width', 'kk-boxed' );
$kk_hp = false;
?>

<?php $title_type = kktfwp_title_type(); ?>

   <!-- start content wrapper -->			
	<div class="content clearfix">
		<?php if( $title_type == 'parallax' ) : ?>
			
		<div id="kk-parallax-wrapper" class="kk-parallax-wrapper">
			
			<?php echo kktfwp_parallax(); ?>

			<div id="kk-parallax-title-wrapper" class="kk-parallax-title-wrapper">
				<div id="kk-parallax-title" class="page-title">
					<h1><?php echo esc_html($term->name); ?></h1>
				</div>	
			</div>	
			
			<a id="kk-down" class="kk-down is-loading" href="#kk-to-me"></a>
		
		</div>				
		<?php endif; ?>
		
		<div class="content-inner-wrapper clearfix">
			<span id="kk-to-me"></span>	
		<?php if( $title_type == 'default' ) { ?>
			<div class="page-title">
				<h1><?php echo esc_html($term->name); ?></h1>
			</div>
			
			<div class="divider clear"></div>	
		<?php } ?>
		
		<!-- start gallery items -->			
		<div class="gallery-wrapper">
				<ul class="isotope-container" id="three-col-p">
				
					<?php $args = array(
						'post_type' => 'gallery',
						'gallery-type' => $term->slug,
						'posts_per_page' => -1
					);
					$query = new WP_Query( $args );

					while ( $query->have_posts() ) : $query->the_post();  ?>
					
					<?php 
						$terms =  get_the_terms( $post->ID, 'gallery-type' ); 
						$term_list = '';
								
						if( is_array($terms) ) {
							foreach( $terms as $term ) {
								$term_list .= $term->slug;
								$term_list .= ' ';
							}
						}
						
						switch( rwmb_meta( '_kk_linkTo' ) ) {
							case 'page':
								$postUrl = get_permalink( rwmb_meta( '_kk_linkToPage' ) );
								break;
							case 'custom':
								$postUrl = rwmb_meta( '_kk_customUrl' );									
								break;
							default:
								$postUrl = get_the_permalink();								
						}
					?>					
					
					<!-- start work -->
					<li id="<?php echo the_ID()?>" <?php post_class("$term_list isotope-item all"); ?> >

						<div class="portfolio-thumb effect-zoom linkto">	
							<a class="img-loading" href="<?php echo esc_attr( $postUrl ) ?>" <?php if ( rwmb_meta( '_kk_newTab' ) && rwmb_meta( '_kk_linkTo' ) !== 'default' ) echo 'target="_blank"'; ?> >							
								<?php if( has_post_thumbnail() ): ?>								
										<?php echo get_the_post_thumbnail( get_the_id(), 'kktfwp-s', array( 'class' => 'responsively-lazy-img', 'data-lazy-load' => 1 ) ); ?>
									<?php endif; ?>
								<span class="kk-n"><?php _e('View','toppic'); ?></span>			
							</a>
						</div> 

						<div class="portfolio-title">
							<h2>
								<a href="<?php echo esc_attr( $postUrl ) ?>" <?php if ( rwmb_meta( '_kk_newTab' ) && rwmb_meta( '_kk_linkTo' ) !== 'default' ) echo 'target="_blank"';?> >
									<?php the_title(); ?>
								</a>
							</h2>
						</div>	
						<?php if (function_exists('printLikes')) { ?>
							<div class="kk-likes-portfolio">
								<?php printLikes(get_the_ID()); ?>
							</div>
						<?php } ?>
					</li>
					
					
					<?php endwhile;?>
					<!-- end work -->
					<li id="kk-item-helper"></li>
					<li id="kk-item-helper"></li>
				</ul>
		</div>
		<!-- end latest work -->
				
		</div>
		
		<?php get_template_part('extends/footer-area') ?>
		
	</div>
	<!-- end content wrapper -->

<?php get_footer(); ?>