<?php
/*

Template Name: Custom Rooms

*/
?>

<?php if(isset($_REQUEST["um_page"])):
 			if(isset($_POST["paged"])):?>
 			
 				<?php 
 					$paged = $_POST["paged"]; 
 					$display = get_field('display'); 
      			    $args = array();
					
					if($display == 'category'){
      			    		
      			    	$custom_cat = get_field('categories'); 
					 	$args = array(
				                   	'post_type' => 'room_post',
									'orderby'	=>	'menu_order date',
									'order' 	=> 	'DESC',
									'paged'     => $paged,
				                    'tax_query' => array(
				                        array(
				                            'taxonomy' => 'room_categories',
				                            'field' => 'ID',
				                            'terms' => $custom_cat
				                        )
				                    )
				                );
						
					}
					elseif($display == 'all')
					{
						$args = array(
									'post_type' => 'room_post',
									'orderby'	=>	'menu_order date',
									'order' 	=> 	'DESC',
									'paged'     => $paged
								);
					
					}
					
 				?>
 				
 				  <?php if($display == "filter"): ?>
	             	
	             	  <?php $posts = get_field('custom', get_queried_object_id()); ?>
	             	  <?php if($posts):?>
		                  <?php foreach($posts as $post):?>
		                        <?php if (!is_numeric($post)):?>
			                            <?php setup_postdata($post);?>

										<div class="col-md-4 um_in animated">
					                        <article class="theBox roomsBox mainBgColor">
					                            <div class="boxContent">
					
													<?php if(has_post_thumbnail()): ?>
					                               		<a href="<?php the_permalink(); ?>">
					                               		<?php the_post_thumbnail('blogMasonry'); ?>	
				                               			</a>
					                            	<?php endif; ?>
					                            </div>
					                            <footer>
					                                <div class="roomTitle um_left">
					                                    <a href="<?php the_permalink(); ?>"><h5 class="title titleUp"><?php the_title(); ?></h5></a>
					                                    <h6><?php the_field('price_label'); ?></h6>
					                                </div>
					                                <div class="roomIcons um_right">
					                                    <div class="boxIcons list-unstyled list-inline text-right">
					                                        <a class="iconHolder brandHover text-center um_expand_lightbox" data-postID="<?php echo $post->ID; ?>" href="#"><i class="fa fa-expand"></i></a>
				                                             <?php 
																$redirectClass = 'um_book';
																if(get_field('redirect_to') != "booking"){
																	$redirectClass = '';	
																}
															 ?>
			                                        		<a class="iconHolder brandHover text-center <?php echo $redirectClass; ?>" data-postID="<?php echo $post->ID; ?>" href="<?php the_field('shop_link'); ?>"><i class="fa fa-bookmark-o"></i></a>
				                                        
					                                        
					                                    </div>
					                                </div>
					                            </footer>
					                        </article>
					                    </div>    
                              <?php endif;?>
		                  <?php endforeach;?>
					<?php endif;?>
		        <?php else: ?> 	
		        	<?php 
	    				$the_Query = new WP_Query($args);
							while ($the_Query->have_posts()):
								$the_Query->the_post();
		        	 ?>
		        				
        					<div class="col-md-4 um_in animated">
			                        <article class="theBox roomsBox mainBgColor">
			                            <div class="boxContent">
			
											<?php if(has_post_thumbnail()): ?>
			                               		<a href="<?php the_permalink(); ?>">
			                               		<?php the_post_thumbnail('blogMasonry'); ?>	
		                               			</a>
			                            	<?php endif; ?>
			                            </div>
			                            <footer>
			                                <div class="roomTitle um_left">
			                                    <a href="<?php the_permalink(); ?>"><h5 class="title titleUp"><?php the_title(); ?></h5></a>
			                                    <h6><?php the_field('price_label'); ?></h6>
			                                </div>
			                                <div class="roomIcons um_right">
			                                    <div class="boxIcons list-unstyled list-inline text-right">
			                                        <a class="iconHolder brandHover text-center um_expand_lightbox" data-postID="<?php echo $post->ID; ?>" href="#"><i class="fa fa-expand"></i></a>
		                                             <?php 
														$redirectClass = 'um_book';
														if(get_field('redirect_to') != "booking"){
															$redirectClass = '';	
														}
													 ?>
	                                        		<a class="iconHolder brandHover text-center <?php echo $redirectClass; ?>" data-postID="<?php echo $post->ID; ?>" href="<?php the_field('shop_link'); ?>"><i class="fa fa-bookmark-o"></i></a>
		                                                     
			                                    </div>
			                                </div>
			                            </footer>
			                        </article>
			                    </div>   

        	          <?php endwhile; ?> 
				<?php endif; ?>
 				
 				
 				
 		
		<?php endif;
	die();
endif;  ?>

<?php get_header(); ?>

<?php wp_reset_postdata(); ?>

<?php $featuredImageType = get_field('background_image_type'); ?>
<?php setBgImg();  ?>

<main class="content roomsPage <?php echo $featuredImageType;  ?>">
	
		<section class="pageImage">
			<?php if($featuredImageType == "bgImg"): ?>	
				<div class="fullBg"></div>
			<?php elseif($featuredImageType == "headerImg"): ?>
				<div class="um_parallax" data-velocity="-.1"></div>
			<?php endif; ?>
		</section>
	
        <div class="container">
            <div class="row">
                <section class="pageTitle text-center">
                	<div class="um_helper">
                		<div class="um_middle">
                			<h3 class="title pageTitle titleUp"><?php the_title(); ?></h3>
                		</div>
                	</div>
                    
                </section>
                
                
               
                 <?php  	
             		$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
              		$display = get_field('display'); 
      			    $args = array();
					
      			    if($display == 'category'){
      			    		
      			    	$custom_cat = get_field('categories'); 
					 	$args = array(
				                   	'post_type' => 'room_post',
									'orderby'	=>	'menu_order date',
									'order' 	=> 	'DESC',
									'paged'     => $paged,
				                    'tax_query' => array(
				                        array(
				                            'taxonomy' => 'room_categories',
				                            'field' => 'ID',
				                            'terms' => $custom_cat
				                        )
				                    )
				                );
						
					}
					elseif($display == 'all')
					{
						$args = array(
									'post_type' => 'room_post',
									'orderby'	=>	'menu_order date',
									'order' 	=> 	'DESC',
									'paged'     => $paged
								);
					
					}
      			    
  			    ?>
                
                <div class="um_articlesWrapper">
                  <section class="articles">
	
	
	             <?php if($display == "filter"): ?>
	             	
	             	  <?php $posts = get_field('custom', get_queried_object_id()); ?>
	             	  <?php if($posts):?>
		                  <?php foreach($posts as $post):?>
		                        <?php if (!is_numeric($post)):?>
			                            <?php setup_postdata($post);?>

										<div class="col-md-4 um_in animated">
					                        <article class="theBox roomsBox mainBgColor">
					                            <div class="boxContent">
					
													<?php if(has_post_thumbnail()): ?>
					                               		<a href="<?php the_permalink(); ?>">
					                               		<?php the_post_thumbnail('blogMasonry'); ?>	
				                               			</a>
					                            	<?php endif; ?>
					                            </div>
					                            <footer>
					                                <div class="roomTitle um_left">
					                                    <a href="<?php the_permalink(); ?>"><h5 class="title titleUp"><?php the_title(); ?></h5></a>
					                                    <h6><?php the_field('price_label'); ?></h6>
					                                </div>
					                                <div class="roomIcons um_right">
					                                    <div class="boxIcons list-unstyled list-inline text-right">
					                                        <a class="iconHolder brandHover text-center um_expand_lightbox" data-postID="<?php echo $post->ID; ?>" href="#"><i class="fa fa-expand"></i></a>
				                                             <?php 
																$redirectClass = 'um_book';
																if(get_field('redirect_to') != "booking"){
																	$redirectClass = '';	
																}
															 ?>
			                                        		<a class="iconHolder brandHover text-center <?php echo $redirectClass; ?>" data-postID="<?php echo $post->ID; ?>" href="<?php the_field('shop_link'); ?>"><i class="fa fa-bookmark-o"></i></a>
				                                        
					                                        
					                                    </div>
					                                </div>
					                            </footer>
					                        </article>
					                    </div>    
                              <?php endif;?>
		                  <?php endforeach;?>
					<?php endif;?>
		        <?php else: ?> 	
		        	<?php 
	    				$the_Query = new WP_Query($args);
							while ($the_Query->have_posts()):
								$the_Query->the_post();
		        	 ?>
		        				
        					<div class="col-md-4 um_in animated">
			                        <article class="theBox roomsBox mainBgColor">
			                            <div class="boxContent">
			
											<?php if(has_post_thumbnail()): ?>
			                               		<a href="<?php the_permalink(); ?>">
			                               		<?php the_post_thumbnail('blogMasonry'); ?>	
		                               			</a>
			                            	<?php endif; ?>
			                            </div>
			                            <footer>
			                                <div class="roomTitle um_left">
			                                    <a href="<?php the_permalink(); ?>"><h5 class="title titleUp"><?php the_title(); ?></h5></a>
			                                    <h6><?php the_field('price_label'); ?></h6>
			                                </div>
			                                <div class="roomIcons um_right">
			                                    <div class="boxIcons list-unstyled list-inline text-right">
			                                        <a class="iconHolder brandHover text-center um_expand_lightbox" data-postID="<?php echo $post->ID; ?>" href="#"><i class="fa fa-expand"></i></a>
		                                             <?php 
														$redirectClass = 'um_book';
														if(get_field('redirect_to') != "booking"){
															$redirectClass = '';	
														}
													 ?>
	                                        		<a class="iconHolder brandHover text-center <?php echo $redirectClass; ?>" data-postID="<?php echo $post->ID; ?>" href="<?php the_field('shop_link'); ?>"><i class="fa fa-bookmark-o"></i></a>
		                                                     
			                                    </div>
			                                </div>
			                            </footer>
			                        </article>
			                    </div>   

        	          <?php endwhile; ?> 
				<?php endif; ?>
	
	                </section>
                </div>
            </div>
            <!--row-->
            
            <?php if($display != 'filter'): ?>
	            <?php if($the_Query->max_num_pages != 1):?>
						<div class="loadMoreContainer text-center">
							<button class="fadeIn animated loadMoreCustomRooms btn default">
								<span><?php _e('Load More','um_lang'); ?></span>
								<div class="um_spinner">
									<div class="um_bounce1 brandBgColor"></div>
									<div class="um_bounce2 brandBgColor"></div>
									<div class="um_bounce3 brandBgColor"></div>
								</div>
							</button>
						</div>
				<?php endif; ?>
			<?php endif; ?>
        </div>
    </main>
    
<script>
		var pageRoomsCustom = parseInt("<?php echo $paged; ?>");
    	var lastCustomPageRooms = parseInt('<?php echo $the_Query->max_num_pages; ?>');
</script>    
<?php wp_reset_postdata(); ?>
<?php get_footer(); ?>