<?php
/**
 * The template for displaying archive pages.
 *
 * Learn more: http://codex.wordpress.org/Template_Hierarchy
 *
 * @package daisy
 */
get_header(); ?>
	<!-- Blog Body 
    ====================================-->
	<?php
		if( get_theme_mod('rst_cat_pagenavi') ){
			$pagenavi = get_theme_mod('rst_cat_pagenavi');
		}else{
			$pagenavi = get_theme_mod('rst_general_pagenavi') ? get_theme_mod('rst_general_pagenavi') : 1;
		}
		//var_dump($pagenavi);
	?>
    <div id="tf-content">
        <div class="container"><!-- Container -->
			<?php
				if( get_theme_mod('rst_cat_template') ){ 					
					$template = get_theme_mod('rst_cat_template');				
				}else{		
					$template = get_theme_mod('rst_general_template') ? get_theme_mod('rst_general_template') : 'large';	
				}				
				if( get_theme_mod('rst_cat_layout') ){			
					$layout = get_theme_mod('rst_cat_layout');							
				}else{			
					$layout = get_theme_mod('rst_general_layout') ? get_theme_mod('rst_general_layout') : 1;		
				}
			?>
            <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 
					$class = "";
					if( $layout == 1  && $template == 'large') {
						$class .= 'col-md-10 col-md-offset-1 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;
					if( get_theme_mod('rst_cat_numberpost') == null ) {
						$post_per_page = get_theme_mod('rst_general_numberpost') ? get_theme_mod('rst_general_numberpost') : get_option('posts_per_page');
					}else{
						$post_per_page = get_theme_mod('rst_cat_numberpost');
					}
					if( get_theme_mod('rst_general_numberpost') == null && get_theme_mod('rst_cat_numberpost') == null){
						$post_per_page = get_option('posts_per_page');
					}					
					
					$args = array(
						'posts_per_page' 	=> absint($post_per_page),
						'paged' 			=> max( get_query_var( 'paged' ), get_query_var( 'page' ))
					);
					$args = array_merge( $wp_query->query_vars, $args );
					$the_query = new WP_Query( $args );
					$wp_query = $the_query;
				?>
				<?php
					global $rst_blog;
					if( get_theme_mod('rst_cat_column') ) {					
						$column = get_theme_mod('rst_cat_column');					
					}else{						
						$column = get_theme_mod('rst_general_column') ? get_theme_mod('rst_general_column') : 2;		
					}
					
					if( get_theme_mod('rst_cat_excerpt_length') == null ) {
						$excerpt_length = get_theme_mod('rst_general_excerpt_length');
					}else{
						$excerpt_length = get_theme_mod('rst_cat_excerpt_length');
					}
					
					//$column = get_theme_mod('rst_cat_column') ? get_theme_mod('rst_cat_column') : 3;
					$rst_blog = array(
						'layout'		=> $layout,
						'template'		=> $template,
						'column' 			=> $column,
						'post_per_page'		=> $numberpost,
						'excerpt_length'	=> $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 -->
					<div id="tf-page-header">
						<h5><?php rst_the_translate('read more posts by','translation_read_more_author') ?></h5>
						<hr>
						<h2><?php the_author()?></h2>
					</div>
					<?php 
						if( $template == 'grid' ) {
							$class_grid = "rst-grid";
						}else{
							$class_grid= " ";
						}
					?>
					<div class="row <?php echo $class_grid ?> <?php echo ( $pagenavi == 3 ? 'rst-inner-ajax' : '' ); ?>  column-<?php echo sanitize_html_class($column) ?>">
					
					<?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><!-- end Pagination -->
				</div><!-- End of Posts/Blogrol -->
				<?php
					if( $layout == 2 || $layout == 3 ) {
				?>
					<?php get_sidebar(); ?>
				<?php
					}
				?>
            </div><!-- end Row -->
        </div><!-- End Container -->
    </div>
<?php get_footer(); ?>