<?php
/**
 * Template Name: Gallery Listing
 *
 * @package WordPress
 * @subpackage Charity
 * @since Charity 1.0
 */
?>
<?php get_header(); ?>
<?php
	$wplook_page_meta 			=  get_post_meta($post->ID);
	$wplook_page_subtitle 		=  isset($wplook_page_meta['wpl_page_subtitle'][0]) ? $wplook_page_meta['wpl_page_subtitle'][0] : "";
	$wplook_sidebar_position 	=  isset($wplook_page_meta['wpl_cpt_sidebar_position'][0]) ? $wplook_page_meta['wpl_cpt_sidebar_position'][0] : "right";
	$wplook_page_sidebar  		=  (isset($wplook_page_meta['wpl_cpt_sidebar_select'][0]) && $wplook_page_meta['wpl_cpt_sidebar_select'][0] != '') ? $wplook_page_meta['wpl_cpt_sidebar_select'][0] : "gallery-1";
	$wplook_page_header 		= (isset($wplook_page_meta['wpl_page_header'][0]) && $wplook_page_meta['wpl_page_header'][0] != '') ? $wplook_page_meta['wpl_page_header'][0] : false;
 ?>
	<div class="main">
		<div class="main-head">
			<div class="main-head-image fullscreener">
				<?php
					if ( $wplook_page_header ) {
						echo '<img class="hide" src="'.esc_url( $wplook_page_header ).'">';
					}?>
			</div><!-- /.main-head-image fullscreener -->

			<div class="main-head-content">
				<div class="grid-container">
					<div class="grid-x grid-margin-x">
						<div class="cell small-12">
							<h1 class="main-title main-title-alt"><?php the_title(); ?></h1><!-- /.main-title main-title-alt -->
							<?php if (ot_get_option('wpl_breadcrumbs_status') == 'on') : ?>
								<ul class="breadcrumbs">
									<?php wplook_breadcrumbs(); ?>
								</ul><!-- /.breadcrumbs -->
							<?php endif; ?>
						</div><!-- /.cell small-12 -->
					</div><!-- /.grid-x grid-margin-x -->
				</div><!-- /.grid-container -->
			</div><!-- /.main-head-content -->
		</div><!-- /.main-head -->

<?php
	$args = array(
	 'post_type' => 'post_gallery',
	 'post_status' => 'publish',
	 'posts_per_page' => ot_get_option('wpl_gallery_per_page'),
	 'paged'=> $paged,
	 );

	$wp_query = null;
	$wp_query = new WP_Query( $args );
?>

		<div class="main-body">
			<div class="grid-container">
				<div class="grid-x grid-margin-x">
					<div class="content cell small-12 <?php if ( $wplook_sidebar_position == 'right') { echo "large-8";} elseif ( $wplook_sidebar_position == 'disable' ) {echo "large-12"; } else { echo " large-8 right";} ?>">

						<div class="grid-x grid-margin-x">

							<?php if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>

								<div class="cell small-12 medium-6 <?php if ( $wplook_sidebar_position == 'disable' ) { echo "large-4"; } else { echo "large-6";}?>">
									<div class="cptlist">
										<div class="cptlist-image">
											<a href="<?php the_permalink(); ?>">
												<?php
												if ( has_post_thumbnail() ) {
													the_post_thumbnail( 'medium-event', array( 'itemprop' => 'image' ) );
												}?>
											</a>
										</div><!-- /.cptlist-image -->

										<h4 class="cptlist-title">
											<a href="<?php the_permalink(); ?>" itemprop="name"><?php the_title(); ?></a>
										</h4><!-- /.cptlist-title -->

										<div class="cptlist-meta">
											<span><i class="far fa-calendar-alt"></i> <?php the_time( get_option( 'date_format' ) ); ?></span>
											<span><i class="far fa-user"></i> <?php the_author(); ?></span>
										</div><!-- /.cptlist-meta -->

										<div class="cptlist-entry">
											<p itemprop="description">
												<?php echo wplook_short_excerpt(ot_get_option('wpl_gallery_excerpt_limit')); ?>
											</p>
										</div><!-- /.cptlist-entry -->
										<div class="event-actions">
											<a href="<?php the_permalink(); ?>" class="button"><?php _e('View gallery', 'charity-wpl'); ?></a>
										</div><!-- /.event-actions -->
									</div><!-- /.cptlist -->
								</div>

							<?php endwhile; ?>
							<?php else : ?>
								<div class="cell small-12">
									<h2><?php _e('Sorry, no posts matched your criteria.', 'charity-wpl'); ?></h2>
									<p><?php _e('Try again later.', 'charity-wpl'); ?></p>
								</div><!-- /.cell -->
							<?php endif; ?>
							<?php wp_reset_postdata(); ?>

						</div><!-- /.grid-x grid-margin-x -->

						<div class="grid-x grid-margin-x">
							<div class="cell">
								<?php wplook_pagination() ?>
							</div>
						</div><!-- /.grid-x grid-margin-x -->
					</div><!-- /.cell small-12 -->
					
					<?php if ( $wplook_sidebar_position != 'disable') { ?>
						<div id="sidebar" class="cell large-3 large-offset-1">
							<div class="sidebar">
								<?php dynamic_sidebar( $wplook_page_sidebar ); ?>
							</div>
						</div>
					<?php } ?>
				</div><!-- /.grid-x grid-margin-x -->
			</div><!-- /.grid-container -->

		</div><!-- /.main-body -->
	</div><!-- /.main -->
<?php get_footer(); ?>
