<?php
/*
Template Name: User Reviews
*/
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'       => 'gp_user_review',
			'meta_query' => array(
				array(
				   'key' => '_hub_page_id',
				   'value' => $GLOBALS['gp_post_id'],
				   'compare' => '=',
				),
			),
			'posts_per_page' => $GLOBALS['gp_per_page'],
			'paged'          => $GLOBALS['gp_paged'],
		);
		
		$gp_query = new wp_query( $args ); ?>

		<div class="blog-wrapper user-review-wrapper <?php echo sanitize_html_class( $GLOBALS['gp_format'] ); ?> <?php echo sanitize_html_class( $GLOBALS['gp_size'] ); ?>"<?php echo gp_data_properties( 'user-reviews' ); ?>>
			
			<?php if ( $gp_query->have_posts() ) : ?>
								
				<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( 'review', '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(); ?>