<?php
/*
Template Name: News
*/
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();
		
		// Get news posts associated with hub
		if ( redux_post_meta( 'gp', get_the_ID(), 'news_post_association' ) == 'disabled' ) {			
			$GLOBALS['gp_meta_query'] = '';
		} else {
			$GLOBALS['gp_meta_query'] = array( array( 'key' => 'post_association', 'value' => $GLOBALS['gp_hub_id'], 'compare' => 'LIKE' ) );	
			$GLOBALS['gp_meta_key'] = 'post_association';		
		}

		$args = array(
			'post_status' => 'publish',
			'post_type' => 'post',
			'tax_query' => array(
				'relation' => 'AND',
				$GLOBALS['gp_post_cats'],
				array(
					'taxonomy' => 'post_format',
					'field' => 'slug',
					'terms' => array( 'post-format-quote', 'post-format-audio', 'post-format-gallery', 'post-format-image', 'post-format-link', 'post-format-video' ),
					'operator' => 'NOT IN',
				)			
			),		
			'orderby'        => $GLOBALS['gp_orderby_value'],
			'order'          => $GLOBALS['gp_order'],		
			'meta_query' 	 => $GLOBALS['gp_meta_query'],	
			'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 news-wrapper <?php echo sanitize_html_class( $GLOBALS['gp_format'] ); ?> <?php echo sanitize_html_class( $GLOBALS['gp_size'] ); ?>"<?php echo gp_data_properties( 'news-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 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 NEWS WRAPPER -->

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

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

<?php get_footer(); ?>