<?php
/**
 * The main template file.
 *
 * This is the most generic template file in a WordPress theme
 * and one of the two required files for a theme (the other being style.css).
 * It is used to display a page when nothing more specific matches a query.
 * E.g., it puts together the home page when no home.php file exists.
 * Learn more: //codex.wordpress.org/Template_Hierarchy
 *
 * @package TOURIMO
 * @since TOURIMO 1.0
 */

$tourimo_template = apply_filters( 'tourimo_filter_get_template_part', tourimo_blog_archive_get_template() );

if ( ! empty( $tourimo_template ) && 'index' != $tourimo_template ) {

	get_template_part( $tourimo_template );

} else {

	tourimo_storage_set( 'blog_archive', true );

	get_header();

	if ( have_posts() ) {

		// Query params
		$tourimo_stickies  = is_home() ? get_option( 'sticky_posts' ) : false;
		$tourimo_post_type = tourimo_get_theme_option( 'post_type' );
		$tourimo_args      = array(
								'blog_style'     => tourimo_get_theme_option( 'blog_style' ),
								'post_type'      => $tourimo_post_type,
								'taxonomy'       => tourimo_get_post_type_taxonomy( $tourimo_post_type ),
								'parent_cat'     => tourimo_get_theme_option( 'parent_cat' ),
								'posts_per_page' => tourimo_get_theme_option( 'posts_per_page' ),
								'sticky'         => tourimo_get_theme_option( 'sticky_style' ) == 'columns'
															&& is_array( $tourimo_stickies )
															&& count( $tourimo_stickies ) > 0
															&& get_query_var( 'paged' ) < 1
								);

		tourimo_blog_archive_start();

		do_action( 'tourimo_action_blog_archive_start' );

		if ( is_author() ) {
			do_action( 'tourimo_action_before_page_author' );
			get_template_part( apply_filters( 'tourimo_filter_get_template_part', 'templates/author-page' ) );
			do_action( 'tourimo_action_after_page_author' );
		}

		if ( tourimo_get_theme_option( 'show_filters' ) ) {
			do_action( 'tourimo_action_before_page_filters' );
			tourimo_show_filters( $tourimo_args );
			do_action( 'tourimo_action_after_page_filters' );
		} else {
			do_action( 'tourimo_action_before_page_posts' );
			tourimo_show_posts( array_merge( $tourimo_args, array( 'cat' => $tourimo_args['parent_cat'] ) ) );
			do_action( 'tourimo_action_after_page_posts' );
		}

		do_action( 'tourimo_action_blog_archive_end' );

		tourimo_blog_archive_end();

	} else {

		if ( is_search() ) {
			get_template_part( apply_filters( 'tourimo_filter_get_template_part', 'templates/content', 'none-search' ), 'none-search' );
		} else {
			get_template_part( apply_filters( 'tourimo_filter_get_template_part', 'templates/content', 'none-archive' ), 'none-archive' );
		}
	}

	get_footer();
}
