<?php
/**
 * The template for displaying all single posts.
 *
 * @package rst
 */

 /* Template Name: Home */ 

get_header(); 
?>
<?php
	$template_slider = rs::getField('rst_home_slider_hide');
	if( $template_slider == 1 ) {
		get_template_part( 'slider', 'template' );
	}
?>
<?php
	if( rs::getField('rst_home_extend_box_hide') == 1 ) {
		get_template_part( 'content', 'box' );
	}
?>
<!-- Blog Body 
====================================-->
<div id="tf-content">
	<div class="container"><!-- Container -->		
	<?php 		
	$pagenavi = get_theme_mod('rst_general_pagenavi') ? get_theme_mod('rst_general_pagenavi') : 1;			
	$template_customize = get_theme_mod('rst_general_template') ? get_theme_mod('rst_general_template') : 'large';	
	$layout_customize = get_theme_mod('rst_general_layout') ? get_theme_mod('rst_general_layout') : 3;				
	$template = rs::getField('rst_page_home_template') != 'none' ? rs::getField('rst_page_home_template') : $template_customize;			
	$layout = rs::getField('rst_page_home_style') != 0 ? rs::getField('rst_page_home_style') : $layout_customize;		
	?>
		<div class="row<?php echo ( $pagenavi == 3 ? ' rst-wrap-ajax' : '' ); ?><?php echo ( $layout == 2 ? ' has-sidebar-left' : '' ); ?><?php echo ( $layout == 3 ? ' has-sidebar-right' : '' ); ?>"  data-sticky_parent=""><!-- Row -->
			<?php 
				
				//$layout = get_theme_mod('rst_general_layout') ? get_theme_mod('rst_general_layout') : 1;
				$class = "";
				if( $layout == 1  && $template == 'large') {
					$class .= 'col-md-8 col-md-offset-2 rst-content-wrap';
				}
				if( $layout == 1 && $template == 'grid') {
					$class .= 'col-md-12 rst-content-wrap';
				}
				if( $layout == 2 ) {
					$class .= 'col-md-8 pull-right';
				}
				if( $layout == 3 ) {
					$class .= 'col-md-8 pull-left';
				}
			?>
			<?php
				global $wp_query;
				$post_per_page = get_theme_mod('rst_general_numberpost') ? get_theme_mod('rst_general_numberpost') : get_option('posts_per_page');
				
				$args = array(
					'posts_per_page' 	=> absint($post_per_page),
					'paged' 			=> max( get_query_var( 'paged' ), get_query_var( 'page' ))
				);
				$the_query = new WP_Query( $args );
				$wp_query = $the_query;
			?>
			<?php
				global $rst_blog;
				if(rs::getField('rst_page_home_template') == 'grid'){
					$column = rs::getField('rst_page_home_column');
				}
				elseif(rs::getField('rst_page_home_template') != 'none'){
					$column = get_theme_mod('rst_general_column') ? get_theme_mod('rst_general_column') : 2;
				}
				else{
					$column = get_theme_mod('rst_general_column') ? get_theme_mod('rst_general_column') : 2;
				}
				
				$rst_blog = array(
					'layout'		=> get_theme_mod('rst_general_layout') ? get_theme_mod('rst_general_layout') : 1,
					'template'		=> $template ? $template : 'large',
					'column' 			=> $column,
					'post_per_page'		=> get_theme_mod('rst_general_numberpost') ? get_theme_mod('rst_general_numberpost') : get_option('posts_per_page'),
					'excerpt_length'	=> get_theme_mod('rst_general_excerpt_length'),
				);
			?>  
			<?php 
				if( $pagenavi == 3 ) {
					$rstkey =  uniqid();
					global $rst_pagenavi;
					$rst_pagenavi = array(
						'key' 		=> 'rst_'.$rstkey,
						'max-paged'	=> ceil(( $the_query->found_posts - $post_per_page ) / 3)
					);
			?>
			<script type="text/javascript">
				var rst_<?php echo esc_html($rstkey) ?> = new rst_blocks();
				rst_<?php echo esc_html($rstkey) ?>.query = '<?php echo str_replace( '\'', '\\\'', json_encode($args) ) ?>';
				rst_<?php echo esc_html($rstkey) ?>.atts = '<?php echo str_replace( '\'', '\\\'', json_encode($rst_blog) ) ?>';
				rst_<?php echo esc_html($rstkey) ?>.url = '<?php echo admin_url( "admin-ajax.php" ); ?>';
			</script>
			<?php } ?>
			<div class="<?php echo esc_attr($class) ?>"> <!-- Left Content for Blog Posts -->
				<?php 
					if( $template == 'grid' ) {
						$class_grid = "rst-grid column-".sanitize_html_class($column);
					}else{
						$class_grid= " ";
					}
				?>
				<div class="row <?php echo $class_grid ?> <?php echo ( $pagenavi == 3 ? 'rst-inner-ajax' : '' ); ?>">
				<?php if ( $the_query->have_posts() ) : ?>						
					<?php while ($the_query->have_posts() ) : $the_query->the_post(); ?>
						<?php
							/*
							 * Include the Post-Format-specific template for the content.
							 * If you want to override this in a child theme, then include a file
							 * called content-___.php (where ___ is the Post Format name) and that will be used instead.
							 */
							get_template_part( 'content', get_post_format() );
						?>

					<?php endwhile; ?>

				<?php else : ?>
					<?php get_template_part( 'content', 'none' ); ?>
				<?php endif; 
				?>
				</div>
				<div class="text-center"><!-- Pagination -->
					<?php 
						if( $pagenavi == 1 ) {
							rst_the_posts_navigation(); 
						}
						elseif( $pagenavi == 2 ) {
							rst_navigation_prev_next(); 
						}
						elseif( $pagenavi == 3 ) {
							rst_the_posts_navigation_ajax(); 
						}
					?>
				</div>
			</div><!-- #primary -->
			<?php
				if( $layout == 2 || $layout == 3 ) {
			?>
				<?php get_sidebar(); ?>
			<?php
				}
			?>
		</div><!-- end Row -->
	</div><!-- End Container -->
</div>
<?php get_footer(); ?>