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

gp_query_variables();
			
$args = array(
	'post_status' => 'publish',
	'tax_query' => array( 'relation' => 'OR', $GLOBALS['gp_slide_cats'], $GLOBALS['gp_hub_cats'], $GLOBALS['gp_video_cats'], $GLOBALS['gp_post_cats'] ),
	'posts_per_page' => 3,
);

$gp_query = new wp_query( $args ); $counter = 1; if ( $gp_query->have_posts() ) : ?>

	<div id="featured-wrapper">
	
		<div class="gp-container" style="height: <?php echo absint( $GLOBALS['gp_slider_height'] ); ?>px;">

		<?php if ( $gp['title_bg_top_gradient_overlay'] == 'enabled' ) { ?>
			<div class="top-bg-gradient-overlay"></div>
		<?php } ?>

		<?php if ( $GLOBALS['gp_side_gradient_overlay'] == 'enabled' ) { ?>
			<div class="side-bg-gradient-overlay"></div>
		<?php } ?>	

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

			<?php

			gp_get_hub_id( get_the_ID() );
		
			if ( get_post_meta( $GLOBALS['gp_hub_id'], '_wp_page_template', true ) == 'hub-template.php' OR get_post_meta( get_the_ID(), '_wp_page_template', true ) == 'review-template.php' ) {
				$GLOBALS['gp_display_site_rating'] = 1;
				$GLOBALS['gp_display_user_rating'] = 1;
				gp_ratings( $GLOBALS['gp_hub_id'] );
			}

			if ( get_post_meta( $GLOBALS['gp_hub_id'], '_wp_page_template', true ) == 'hub-template.php' ) {
				$GLOBALS['gp_title_bg'] = redux_post_meta( 'gp', get_the_ID(), 'hub_title_bg' );
			} elseif ( get_post_meta( $GLOBALS['gp_hub_id'], '_wp_page_template', true ) == 'review-template.php' ) {
				$GLOBALS['gp_title_bg'] = redux_post_meta( 'gp', get_the_ID(), 'review_title_bg' );
			} else {
				$GLOBALS['gp_title_bg'] = '';
			}	
									
			if ( ! empty( $GLOBALS['gp_title_bg']['url'] ) ) {
			
				 $image = aq_resize( wp_get_attachment_url( gp_get_attachment_id_from_url( $GLOBALS['gp_title_bg']['url'] ) ), $GLOBALS['gp_slider_width'], $GLOBALS['gp_slider_height'], true, false, true );
				if ( $gp['retina'] == 'gp-retina' ) {
					$retina = aq_resize( wp_get_attachment_url( gp_get_attachment_id_from_url( $GLOBALS['gp_title_bg']['url'] ) ), $GLOBALS['gp_slider_width'] * 2, $GLOBALS['gp_slider_height'] * 2, true, true, true );
				} else {
					$retina = '';
				}
				
			} else {

				$image = aq_resize( wp_get_attachment_url( get_post_thumbnail_id( get_the_ID() ) ), $GLOBALS['gp_slider_width'], $GLOBALS['gp_slider_height'], true, false, true );
				if ( $gp['retina'] == 'gp-retina' ) {
					$retina = aq_resize( wp_get_attachment_url( get_post_thumbnail_id( get_the_ID() ) ), $GLOBALS['gp_slider_width'] * 2, $GLOBALS['gp_slider_height'] * 2, true, true, true );
				} else {
					$retina = '';
				}
			
			}
										
			?>				

			<?php if ( isset( $counter ) && $counter % 3 == 1 ) { ?>
				<div class="large-post">
			<?php } elseif ( ( isset( $counter ) && $counter % 3 == 2 ) && $gp_query->current_post != 0 ) { ?>
				<div class="small-posts">
			<?php } ?>

				<?php if ( ! empty( $gp['slide_link'] ) OR $post->post_type == 'post' OR $post->post_type == 'page' ) { ?><a href="<?php if ( $post->post_type == 'gp_slide' ) { echo esc_url( $gp['slide_link'] ); } else { the_permalink(); } ?>"<?php if ( $post->post_type == 'gp_slide' ) { ?> target="<?php echo esc_url( $gp['slide_link_target'] ); ?>"<?php } ?>><?php } ?>

					<div class="featured-post" style="background-image: url(<?php echo esc_url( $image[0] ); ?>);" data-rel="<?php echo esc_url( $retina ); ?>">

						<?php if ( ! empty( $gp['slide_caption_title'] ) OR ! empty( $gp['slide_caption_text'] ) OR $post->post_type == 'post' OR $post->post_type == 'page' ) { ?>

							<div class="featured-caption">

								<?php if ( ( get_post_meta( $GLOBALS['gp_hub_id'], '_wp_page_template', true ) == 'hub-template.php' OR get_post_meta( get_the_ID(), '_wp_page_template', true ) == 'review-template.php' ) && ( $GLOBALS['gp_site_rating_enabled'] == true OR $GLOBALS['gp_user_rating_enabled'] == true ) ) { ?>
									<div class="rating-wrapper">
										<?php if ( $GLOBALS['gp_site_rating_enabled'] == true ) { get_template_part( 'lib/sections/site', 'rating' ); } ?>			
										<?php if ( $GLOBALS['gp_user_rating_enabled'] == true ) { get_template_part( 'lib/sections/user', 'rating' ); } ?>
									</div><!-- END RATING WRAPPER -->
								<?php } ?>
											
								<?php if ( ! empty( $gp['slide_caption_title'] ) OR $post->post_type == 'post' OR $post->post_type == 'page' ) { ?>
									<h2 class="featured-caption-title"><?php if ( $post->post_type == 'gp_slide' ) { echo esc_attr( $gp['slide_caption_title'] ); } else { echo gp_prefix_hub_title( get_the_ID() ); } ?></h2>
								<?php } ?>
	
								<?php if ( ( ! empty( $gp['slide_caption_text'] ) OR $post->post_type == 'post' OR $post->post_type == 'page' ) && ( isset( $counter ) && $counter % 3 == 1 ) ) { ?>
									<div class="featured-caption-text"><?php if ( $post->post_type == 'gp_slide' ) { echo esc_attr( $gp['slide_caption_text'] ); } else { echo gp_excerpt( 100 ); } ?></div>
								<?php } ?>
				
							</div>
	
						<?php } ?>
					
						<?php if ( $GLOBALS['gp_bottom_gradient_overlay'] == 'enabled' ) { ?>
							<div class="bottom-bg-gradient-overlay"></div>
						<?php } ?>
											
					</div>	
					
				<?php if ( ! empty( $gp['slide_link'] ) OR $post->post_type == 'post' OR $post->post_type == 'page' ) { ?></a><?php } ?>

			<?php if ( ( isset( $counter ) && $counter % 3 == 1 ) ) { ?>
				</div>
			<?php } elseif ( ( isset( $counter ) && $counter % 3 == 0 ) OR ( ( ( $gp_query->current_post + 1 ) == $gp_query->post_count ) && $gp_query->current_post != 0 ) ) { ?>
				</div>
			<?php } ?>
			
		<?php $counter++; endwhile; ?>
		
		</div>
		
	</div>

<?php else : ?>

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

<?php endif; wp_reset_postdata(); ?>

<?php if ( ! empty( $gp['header_ad'] ) ) { ?>
	<div id="header-area">
		<div class="gp-container">
			<?php echo do_shortcode( $gp['header_ad'] ); ?>
		</div>
	</div>			
<?php } ?>
		
<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 the_content(); ?>	
		
		<?php endwhile; endif; ?>		

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

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

<?php get_footer(); ?>