<?php
/**
 *
 * Template Name: Home
 *
 */

get_header(); ?>
<div class="row">
	<div class="site-main">
		<div class="columns small-12">
			<div class="header-widget-wrap">

				<div class="row">

					<div class="small-12 columns header-widget" >
				
					<?php if ( is_active_sidebar( 'home-above-hero' ) ) { ?>

						<?php dynamic_sidebar( 'home-above-hero' ); ?>

						<?php } ?>
				
					</div><!-- .small-12 -->

				</div><!-- .row -->

			</div><!-- .header-widget -->
			<?php if ( true == get_theme_mod( 'slider_enabled', true ) ) : ?>
			
			<?php 
				$slider_image = get_theme_mod( 'slider_image', '' );
				$slider_text = get_theme_mod( 'slider_text', '' );
				$slider_link = get_theme_mod( 'slider_link', '' );
			?>
			<div class="orbit" role="region" data-orbit="bj9aii-orbit" data-swipe="false"  data-options="animInFromLeft:fade-in; animInFromRight:fade-in; animOutToLeft:fade-out; animOutToRight:fade-out;" data-resize="y14ai8-orbit" id="y14ai8-orbit">
			  <ul class="orbit-container">
			    <button class="orbit-previous" style='display: none;'>&#9664;&#xFE0E;</button>
			    <button class="orbit-next" style='display: none;' >&#9654;&#xFE0E;</button>
			    
			    	<li class="is-active orbit-slide">
			    		<a href="<?php echo esc_url( $slider_link ); ?>">
						<img class="orbit-image" src="<?php echo esc_url( $slider_image ); ?>" alt="<?php echo esc_attr( $slider_text ); ?>">
						<figcaption class="orbit-caption"><?php echo esc_attr( $slider_text ); ?></figcaption>
						</a>
					</li>
			  </ul>
			</div>
			<?php else : ?> <!-- slider_enabled -->

			<?php endif; ?> <!-- slider_enabled -->
		</div>	
		
		<?php if ( is_active_sidebar('home-below-hero') ) { ?>
				<div class="home-below-hero-widget">
					<div class="columns small-12">
		<?php 			dynamic_sidebar('home-below-hero'); ?>
					</div><!-- .large-12 columns -->
				</div><!-- .home-below-hero-widget columns -->
		<?php } ?>
		
		<div class="columns small-12">
<!-- 
			<div class="featured-posts">
 -->
				
			<div class="home_posts_titles">
				<div class="row">
					
					<div class="large-12 columns">
						
						<?php if ( get_theme_mod( 'home_posts_title' ) ) { 
							$home_posts_title = get_theme_mod( 'home_posts_title' ); ?>
			
							<h2><?php echo esc_attr( $home_posts_title ); ?></h2>
			
						<?php } // end home_posts_title
			
							if ( get_theme_mod( 'home_posts_subtitle' ) ) { 
							$home_posts_subtitle = get_theme_mod( 'home_posts_subtitle' ); ?>
			
							<h3><?php echo esc_attr( $home_posts_subtitle ); ?></h3>
			
						<?php } // end home_posts_subtitle ?>
			
					</div><!-- .large-12 -->
			
				</div><!-- .row -->
			</div><!-- .home_posts_titles -->
			
			<?php if ( true == get_theme_mod( 'home_featured_posts_enabled', true ) ) : ?>
		
			<div class="featured-posts"> 
				<div class="row">
					
					<?php
						// Get chosen category
						$home_posts_cat = esc_attr( get_theme_mod( 'featured_posts_cat' ) );
						$num_home_posts_cat = esc_attr( get_theme_mod( 'num_featured_posts_cat', 3 ) );
						
						if ( $home_posts_cat == 0  ) {
							$args = array (
								'post_type'         => 'post',
								'orderby' => 'post_date',
								'order' => 'DESC',
								'posts_per_page'    => '3',
								'post__not_in'	    => get_option('sticky_posts'),
							);
						} else {
							// WP_Query arguments
							$args = array (
								'post_type'         => 'post',
								'posts_per_page'    => (int) $num_home_posts_cat,
								'cat'         	    => $home_posts_cat,
								'post__not_in'	    => get_option('sticky_posts'),
							);
						}
						
			
						// The Query
						$query = new WP_Query( $args );
			
						// The Loop
						if ( $query->have_posts() ) {
							while ( $query->have_posts() ) {
								$query->the_post(); 
			
								get_template_part( 'template-parts/content', 'home' ); 
							}
			
						} else { 
			
							get_template_part( 'template-parts/content', 'none' ); 
			
						} 
						// Restore original Post Data
						wp_reset_postdata(); 
			
					?>
			
				</div><!-- .row -->
				
			</div><!-- .featured-posts -->
			<?php endif; ?> <!-- featured_posts_enabled -->
			
			<?php if ( true == get_theme_mod( 'home_content_page_enabled', true ) ) : ?>		
				<div class="row">
									
					<div class="columns small-12">
						
						<div class="home-content clearfix">
				
							<?php
								$page_id = esc_attr( get_theme_mod( 'home_content_page' ) );
								if ( $page_id != 0 ) {
								
									$args = array(
									  'page_id' => (int) $page_id,
									);
					
									$query = null;
					
									$query = new WP_Query( $args );
					
									if( $query->have_posts() ) {
									  while ($query->have_posts()) : $query->the_post(); ?>
									    <?php
									   the_content();
									  endwhile;
									}
									
									wp_reset_postdata();  // Restore global post data
								}
								
							?>
				
						</div><!-- .home-content -->
				
					</div><!-- .large-12 -->
				
				</div><!-- row -->
			<?php endif; ?> <!-- home_content_page_enabled -->
			
		</div><!-- columns small-12 -->
	</div><!-- .site-main -->	
</div><!-- .row -->


<?php get_footer(); ?>