<?php
/*
 * Template Name: Template timeline
 */
?>
<?php
get_header();
get_template_part('template_inc/inc', 'header');
get_template_part('template_inc/inc', 'breadcrumb');
?>

<?php


$interiart_title = get_post_meta(get_the_ID(), 'tz_timeLine_title', true);
$interiart_catid = get_post_meta(get_the_ID(), 'tz_timeLine_catid', true);
$interiart_limit = get_post_meta(get_the_ID(), 'tz_timeLine_limit', true);
$interiart_orderby = get_post_meta(get_the_ID(), 'tz_timeLine_orderby', true);
$interiart_order = get_post_meta(get_the_ID(), 'tz_timeLine_order', true);
$interiart_paging = get_post_meta(get_the_ID(), 'tz_interiart_paging', true);
$interiart_load_text = get_post_meta(get_the_ID(), 'tz_interiart_ajaxbutton_text', true);




?>
    <div class="tzPortfolio_Container tztimeLine">
        <?php if ($interiart_title != '') : ?>
            <div class="tz_title">
                <h3><?php echo esc_attr($interiart_title); ?></h3>
            </div>
        <?php endif; ?>
        <div class="container">
            <div class="tzPortfolio">
                <?php
                if (get_query_var('paged')):
                    $interiart_paged = get_query_var('paged');
                else:
                    $interiart_paged = 1;
                endif;

                if ($interiart_catid != '') {
                    $interiart_cat = array();
                    if (is_array($interiart_catid)) {
                        sort($interiart_catid);
                        $interiart_count_cat = count($interiart_catid);

                        for ($i = 0; $i < $interiart_count_cat; $i++) {
                            $interiart_cat[] = (int)$interiart_catid[$i];
                        }

                    } else {
                        $interiart_cat[] = (int)$interiart_catid;
                    }
                    $args = array(
                        'post_type' => 'post',
                        'paged' => $interiart_paged,
                        'posts_per_page' => $interiart_limit,
                        'orderby' => $interiart_orderby,
                        'order' => $interiart_order,
                        'tax_query' => array(
                            array(
                                'taxonomy' => 'category',
                                'filed' => 'id',
                                'terms' => $interiart_cat
                            )
                        )
                    );
                } else {
                    $args = array(
                        'post_type' => 'post',
                        'paged' => $interiart_paged,
                        'posts_per_page' => $interiart_limit,
                        'orderby' => $interiart_orderby,
                        'order' => $interiart_order,
                    );
                }

                $query = new WP_Query($args);
                if ($query->have_posts()): while ($query->have_posts()): $query->the_post();

                    $interiart_post_history_date = get_post_meta(get_the_ID(), 'interiart_post_history_date', true);
                    $interiart_post_history_month = get_post_meta(get_the_ID(), 'interiart_post_history_month', true);
                    $interiart_post_history_year = get_post_meta(get_the_ID(), 'interiart_post_history_year', true);

                    ?>
                    <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                        <div class="tzTimelineInner">
                            <div class="tzTimelineImage col-md-6">
                                <?php the_post_thumbnail(); ?>
                            </div>
                            <div class="tzTimelineContent col-md-6">
<!--                                 <span class="tzInfomation">-->
<!--                                     <small class="tz_year">--><?php //echo get_the_date('Y'); ?><!--</small>-->
<!--                                     <small class="tz_month">--><?php //echo get_the_date('M j'); ?><!--</small>-->
                                     <small class="tz_year"><?php echo esc_attr($interiart_post_history_year); ?></small>
                                     <small class="tz_month"><?php  echo esc_attr($interiart_post_history_month); ?> <?php echo esc_attr($interiart_post_history_date); ?></small>

<!--                                 </span>-->
                                <h3 class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>

                                <?php
                                if (!has_excerpt()) {
                                    the_content(sprintf('<a href="%s" class="tzreadmore">%s</a>', esc_url(get_permalink()), esc_html__('read more', 'interiart'), false));
                                    wp_link_pages();
                                } else {
                                    the_excerpt();
                                }
                                ?>
                            </div>
                        </div>
                    </div>
                <?php
                endwhile; // end while have posts
                    wp_reset_postdata();
                endif;  // end if have posts
                ?>
            </div><!--end class tzPortfolio-->
        </div><!--end class container-->
        <?php

        $interiart_load_class = '';
        if ($interiart_paging != 'pagenavi'):
            $interiart_load_class = "class =not_pagenavi";
        endif;

        $interiart_ajaxbutton_class = '';
        if ($interiart_paging != 'ajaxbutton'):
            $interiart_ajaxbutton_class = "class =not_pagenavi";
        endif;


        ?>
        <div class="tz_timeline_nav">
            <div id="tz_append" <?php echo esc_attr($interiart_ajaxbutton_class); ?>>
                <a href="#tz_append"><?php echo esc_html($interiart_load_text); ?></a>
            </div><!--end id tz_append-->
            <div id="loadajax" <?php echo esc_attr($interiart_load_class); ?>>
                <?php echo interiart_custom_paging_nav($query->max_num_pages);  ?>
            </div>
        </div>
    </div>


<?php
interiart_footer_type();
get_footer();
?>