<?php
/*
Template Name: Gallery
*/

get_header();
global $ththeme_option;
if(empty(get_the_post_thumbnail_url())){

	$thumbnail_url = $ththeme_option['page-title-background']['url'];
} else $thumbnail_url = get_the_post_thumbnail_url();
$galleries = new WP_Query( array('post_type' => 'ththeme_galleries', 'posts_per_page' => 100, 'orderby' => 'publish_date', 'order' => 'DESC'  ) );
?>

	<!-- Page header -->
	<div class="logisco-page-title-wrap  logisco-style-custom logisco-center-align" style="background-image: url(<?php echo $thumbnail_url; ?>) ;">
        <div class="logisco-header-transparent-substitute"></div>
        <div class="logisco-page-title-overlay"></div>
        <div class="logisco-page-title-container logisco-container">
            <div class="logisco-page-title-content logisco-item-pdlr">
                <h1 class="logisco-page-title" style="font-size: 44px ;text-transform: none ;letter-spacing: 0px ;"><?php the_title(); ?></h1>
            </div>
        </div>
    </div>
	<div class="logisco-page-wrapper" id="logisco-page-wrapper">
        <div class="gdlr-core-page-builder-body">
		<?php if($galleries->have_posts()): ?>
			<?php
			$n = 0;
			while ( $galleries->have_posts() ) : $galleries->the_post();
				$images = get_post_meta(get_the_ID(), 'upload_gallery', true);
				$images_id = explode(",", $images);
				if ($images_id[0] != "") {
    				if (is_array($images_id) || is_object($images_id)) {
			?>
			<div class="gdlr-core-pbf-wrapper " style="padding: padding: 0px 0px 30px 0p;">
                <div class="gdlr-core-pbf-wrapper-content gdlr-core-js ">
                    <div class="gdlr-core-pbf-wrapper-container clearfix gdlr-core-pbf-wrapper-full-no-space">
                        <div class="gdlr-core-pbf-element">
                            <div class="gdlr-core-title-item gdlr-core-item-pdb clearfix  gdlr-core-center-align gdlr-core-title-item-caption-bottom gdlr-core-item-pdlr" style="padding-bottom: 60px ;">
                                <div class="gdlr-core-title-item-title-wrap ">
                                    <h3 class="gdlr-core-title-item-title gdlr-core-skin-title " style="text-transform: none ;"><?php the_title(); ?><span class="gdlr-core-title-item-title-divider gdlr-core-skin-divider"></span></h3>
                                </div>
                                <span class="gdlr-core-title-item-caption gdlr-core-info-font gdlr-core-skin-caption" style="font-style: normal ;"><?php the_excerpt(); ?></span>
                            </div>
                        </div>
                        <div class="gdlr-core-pbf-element">
                            <div class="gdlr-core-gallery-item gdlr-core-item-pdb clearfix  gdlr-core-gallery-item-style-grid-no-space gdlr-core-item-pdlr ">
                                <div class="gdlr-core-gallery-item-holder gdlr-core-js-2 clearfix" data-layout="fitrows">
                                <?php foreach( $images_id as $image ): ?>
                                	<?php
                                	$n++;
                                	if($n == 1){
                                		$class = 'gdlr-core-column-first';
                                	} else $class = '';
                                	$size = array( 400, 600, 'bfi_thumb' => true );
                                	$image_url = wp_get_attachment_image_src($image, 'full');
                                	$image_crop = wp_get_attachment_image_src($image, $size);
                                	?>
                                    <div class="gdlr-core-item-list gdlr-core-gallery-column  gdlr-core-column-15 <?php echo $class; ?> gdlr-core-item-mgb">
                                        <div class="gdlr-core-gallery-list gdlr-core-media-image">
                                            <a class="gdlr-core-lightgallery gdlr-core-js " href="<?php echo $image_url[0]; ?>" data-lightbox-group="gdlr-core-img-group-1"><img src="<?php echo $image_crop[0]; ?>" alt="<?php the_title(); ?>" title="<?php the_title(); ?>"><span class="gdlr-core-image-overlay "><i class="gdlr-core-image-overlay-icon gdlr-core-size-22 fa fa-search"></i></span></a>
                                        </div>
                                    </div>
                                    <?php endforeach; ?>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
			<?php
				}
			}
			endwhile;
			?>
		<?php endif; ?>
        </div>
    </div>

<?php
get_footer();