<?php
/**
 * The front page template file.
 *
 *
 * @package Royal
 */?> 
<?php 
	if( 'posts' == get_option( 'show_on_front' ) ) {
	    get_template_part('home');
	} else { 

get_header(); 
	if ( get_theme_mod('page-builder' ) ) { 
		if( get_theme_mod('flexslider') ) {   
			echo do_shortcode( get_theme_mod('flexslider'));
		} ?>

		<div id="content" class="site-content">
		   <div class="container">	
			<?php  if( get_theme_mod('home_sidebar',false ) ) { ?>
				<div id="primary" class="content-area eleven columns">
			<?php }else { ?> 
			    <div id="primary" class="content-area sixteen columns">
			<?php } ?>
				<main id="main" class="site-main" role="main">
					<?php
						while ( have_posts() ) : the_post();
							the_content();
						endwhile;
					?>
					
			     </main><!-- #main -->
		     </div><!-- #primary -->
<?php	} else {

        if( get_theme_mod('enable_slider',true) ) { 
	        get_template_part('category-slider');
        } 
        
	 ?>
	<div id="content" class="site-content">
		<div class="container">		
	<?php  if( get_theme_mod('home_sidebar',false ) ) { ?>
				<div id="primary" class="content-area eleven columns">
			<?php }else { ?>
			    <div id="primary" class="content-area sixteen columns">
			<?php } ?>
		<main id="main" class="site-main" role="main">

		<?php
		do_action('royal_service_content_before'); 
			if(get_theme_mod('enable_service',true) ) { 
			$service = get_theme_mod('service_count',3 );
		    $service_pages = array();
		    for ( $i = 1 ; $i <= $service ; $i++ ) {
				$service_page = absint(get_theme_mod('service_'.$i));
				if( $service_page ){
                    $service_pages[] = $service_page;
				}
		    }

			if( $service_pages && !empty( $service_pages ) ) {
				$args = array(
					'post_type' => 'page',
					'post__in' => $service_pages,
					'posts_per_page' => -1 ,
					'orderby' => 'post__in'
				);
		    }else { ?>
			<div class="services-wrapper clearfix">			
				   <div class="one-third column services">	
				        <h4><?php _e('Service Page - 1','royal');?></h4>				 
						<img src="<?php echo esc_url(get_template_directory_uri()); ?>/images/page.png" />								    		
						<p><?php printf( __('You haven\'t created any service page yet. Create Page. Go to <a href="%1$s"target="_blank"> Customizer </a> and click royal Options => Home => Service Section #1 and select page from  dropdown page list.','royal'), admin_url('customize.php') ) ;?></p>						    	
	   				</div> 
	   				<div class="one-third column services">	
				        <h4><?php _e('Service Page-2','royal');?></h4>				 
						<img src="<?php echo esc_url(get_template_directory_uri()); ?>/images/page.png" />								    		
						<p><?php printf( __('You haven\'t created any service page yet. Create Page. Go to <a href="%1$s"target="_blank"> Customizer </a> and click royal Options => Home => Service Section #2 and select page from  dropdown page list.','royal'), admin_url('customize.php') ) ;?></p>						    	
	   				</div> 
	   				<div class="one-third column services">	
				        <h4><?php _e('Service Page-3','royal');?></h4>				 
						<img src="<?php echo esc_url(get_template_directory_uri()); ?>/images/page.png" />								    		
						<p><?php printf( __('You haven\'t created any service page yet. Create Page. Go to <a href="%1$s"target="_blank"> Customizer </a> and click royal Options => Home => Service Section #3 and select page from  dropdown page list.','royal'), admin_url('customize.php') ) ;?></p>						    	
	   				</div> 			
			</div>
					
	<?php  }

  if( isset($args) ) :
		$query = new WP_Query($args);
		if( $query->have_posts()) : ?>
			<div class="services-wrapper">
		<?php while($query->have_posts()) :
				$query->the_post(); ?>
				    <div class="one-third column services">
				    	<?php the_title( '<h4>', '</h4>' ); ?>
				    	<?php if( has_post_thumbnail() ) : ?>
				    		<a href="<?php echo esc_url( get_permalink() ); ?>" rel="bookmark"><?php the_post_thumbnail('royal_service-thumbnail'); ?></a>
				    	<?php endif; ?>
				    	<?php the_content(); ?>
				    </div>
		<?php endwhile; ?>
		<br class="clear" />
			</div>
		<?php endif; ?>
		<?php  
			$query = null;
			wp_reset_postdata();
			endif;
		}
		
		do_action('royal_service_content_after');
	    royal_recent_posts();  ?>

<?php
	    if( get_theme_mod('enable_home_default_content',false ) ) {  ?>
			<div class="container default-home-page"><?php
				while ( have_posts() ) : the_post();       
					the_content();
				endwhile; ?>
	        </div><?php
	    } ?>

		</main><!-- #main -->
	</div><!-- #primary -->

<?php
}

if( get_theme_mod('home_sidebar',false ) ) { 
   get_sidebar();
}
get_footer();
}  ?>