<?php 
/* 
Template Name: Homepage :: Grid
*/ 
?>

<?php get_header()?>

<?php global $post; ?>
<?php if ( post_password_required( $post ) ) { 

		get_template_part( 'password-form' );
		
	} else { ?>
	<?php if (have_posts()) : ?>
		<?php while (have_posts()) : the_post(); ?>

		<!-- start gallery -->	
		<!-- start main container -->
		<div class="fullmasonry">

			<div class="gallery-full-masonry">
				<ul class="masonry-container">
				<?php 
					$attachments = rwmb_meta( 'kk_grid', 'type=image_advanced' );						

					foreach ($attachments as $attachment) { 
			
						$koto_HomepageGridType = get_post_meta(get_the_ID(), '_kk_homepage_layout_value', true);
						$kktfwp_ratio = '';
					
						if ( $koto_HomepageGridType === 'Random' ) {
							$kktfwp_ratio = wp_get_attachment_image_src( $attachment['ID'], 'full' );
							$kktfwp_ratio = $kktfwp_ratio[2]/$kktfwp_ratio[1] * 100 .'%';
						}	?>
						
						<li id="<?php echo esc_attr($attachment['ID']) ?>" <?php post_class( array( 'masonry-box', esc_attr( strtolower( $koto_HomepageGridType )) ) ); ?> >
							<div class="portfolio-thumb">		
								<a class="kk-lightbox img-loading" data-group="kk-lightbox[<?php the_ID();?>]" href="<?php echo esc_url($attachment['full_url']) ?>" data-title="<?php echo esc_attr($attachment['title']) ?>" style="padding-bottom:<?php echo esc_attr( $kktfwp_ratio ); ?>">
									
									<?php echo wp_get_attachment_image( $attachment['ID'], 'kktfwp-s', '', array( 'class' => 'responsively-lazy-img', 'title' => $attachment['title'], 'data-lazy-load' => 1 ) ); ?>
									
									<span class="kk-n"><?php _e('View','toppic'); ?></span>	
								</a>
							</div>
						</li>
					<?php } ?>
				</ul>
			</div>
			<!-- end gallery -->	
			
		</div>
		<!-- end container -->	
		
		<?php $content = get_the_content();
			
			if(!empty($content)) : ?>
				
			<div class="info-fs-form kk-active-button">
				<!-- start info close icon -->
				<div class="kk-info-close">
						<span></span>
				</div>
				<!-- end info close icon -->
				<div class="content-inner-wrapper">
					<div class="content-child">
						<?php the_content(); ?>
					</div>
				</div>
			</div>
			
		<?php endif; ?>

		<?php endwhile; ?>
	<?php endif; ?>	
<?php } ?>	

<?php get_footer()?>