<?php
/*
Template Name: Blog
*/
get_header(); global $gp; ?>

<?php gp_page_header( get_the_ID() ); ?>

<div id="content-wrapper"<?php if ( $GLOBALS['gp_layout'] != 'gp-fullwidth' ) { ?> class="gp-container"<?php } ?>>

	<div id="content">
	
		<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>	

			<?php if ( isset( $GLOBALS['gp_hub_header'] ) && $GLOBALS['gp_hub_header'] == true ) { ?>
				<header class="entry-header small-header">
					<h2 class="entry-title"><?php echo gp_prefix_hub_title( get_the_ID() ); ?></h2>
				</header>
			<?php } ?>		
			
			<?php the_content(); ?>
			
		<?php endwhile; endif; rewind_posts(); ?>	

		<?php 

		gp_query_variables();
		
		$args = array(
			'post_status'     => 'publish',
			'post_type'       => explode( ',', $GLOBALS['gp_post_types'] ),
			'tax_query'       => array( 'relation' => 'OR', $GLOBALS['gp_hub_cats'], $GLOBALS['gp_video_cats'], $GLOBALS['gp_post_cats'], $GLOBALS['gp_portfolio_cats'], $GLOBALS['gp_slide_cats'] ),
			'orderby'         => $GLOBALS['gp_orderby_value'],
			'order'           => $GLOBALS['gp_order'],
			'meta_key'        => $GLOBALS['gp_meta_key'],
			'posts_per_page'  => $GLOBALS['gp_per_page'],
			'paged'           => $GLOBALS['gp_paged'],
			'date_query' => array( $GLOBALS['gp_date_posted_value'], $GLOBALS['gp_date_modified_value'] ),
		);

		$gp_query = new wp_query( $args ); ?>
				
		<div class="blog-wrapper <?php echo sanitize_html_class( $GLOBALS['gp_format'] ); ?> <?php echo sanitize_html_class( $GLOBALS['gp_size'] ); ?>"<?php echo gp_data_properties( 'blog-template' ); ?>>

			<?php if ( $gp_query->have_posts() ) : ?>
														
				<?php get_template_part( 'lib/sections/filter' ); ?>
	
				<div class="inner-loop <?php echo sanitize_html_class( $gp['ajax'] ); ?>">
								
					<?php while ( $gp_query->have_posts() ) : $gp_query->the_post(); ?>

						<?php if ( get_post_meta( get_the_ID(), '_wp_page_template', true ) == 'review-template.php' OR get_post_meta( get_the_ID(), '_wp_page_template', true ) == 'hub-template.php' OR $post->post_type == 'gp_user_review' ) { 
							get_template_part( 'review', 'loop' ); 
						} else {
							get_template_part( 'post', 'loop' ); 
						} ?>
				
					<?php endwhile; ?>
			
				</div>

				<?php echo gp_pagination( $gp_query->max_num_pages ); ?>

			<?php else : ?>

				<strong class="no-items-found"><?php _e( 'No items found.', 'gp_lang' ); ?></strong>

			<?php endif; wp_reset_postdata(); ?>
				
		</div><!-- END BLOG WRAPPER -->

	</div><!-- END CONTENT -->

	<?php get_sidebar(); ?>
	
</div><!-- END CONTENT WRAPPER -->

<?php get_footer(); ?>