<?php get_header(); ?>

<?php $queried_object = get_queried_object();
$tax = $queried_object->taxonomy;
$name = $queried_object->name;
$term_id = $queried_object->term_id;
$term_name = '';
if ($tax == 'category') $term_name = 'دسته بندی';
if ($tax == 'post_tag') $term_name = 'برچسب'; ?>
<section class="archive-blogz rt">
    <div class="main">
        <div class="title-asli rt">
            <h1 class="name right rt-19 rt-fff rt-bold"><?php echo $term_name . ' ' . $name; ?></h1>
        </div>
        <?php
        $per_page = get_option('posts_per_page');
        $per_page = (!empty($per_page)) ? $per_page : 12;
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $args = array(
            'post_type' => array('post'),
            'post_status' => 'publish',
            'posts_per_page' => $per_page,
            'paged' => $paged,
            'orderby'     => 'post_date',
            'order' => 'DESC',
            'tax_query' => array(
                array(
                    'taxonomy' => $tax,
                    'field' => 'term_id',
                    'terms' => $term_id
                )
            )
        );
        $wp_query = new WP_Query($args); ?>
        <div class="entery rt-relative rt">
            <?php if ($wp_query->have_posts()) :
                while ($wp_query->have_posts()) : $wp_query->the_post();
                    global $post;
                    $post_id = $post->ID;
                    $post_permalink = get_the_permalink($post_id);
                    $post_title = get_the_title($post_id);
                    $post_excerpt = get_the_excerpt($post_id);
                    $post_thumb = (has_post_thumbnail($post_id)) ? true : false;
                    $reading_time = get_the_reading_time($post_id); ?>
                    <article class="mini-post right rt-overflow rt-bg rt-relative rt-10px rt-shadow">
                        <a href="<?php echo $post_permalink; ?>" title="<?php echo $post_title; ?>" rel="bookmark" class="rt rt-relative pic">
                            <?php if ($post_thumb) : the_post_thumbnail('blog_cover', array("class" => "rt", "alt" => $post_title)); ?>
                            <?php else : ?><img src="<?php echo THEME_TEMPLATE_URL . '/assets/front/img/default-thumb.svg'; ?>" alt="<?php echo $post_title; ?>" class="rt"><?php endif; ?>
                        </a>
                        <div class="inside rt">
                            <h2 class="title rt rt-overflow rt-15 rt-bold"><a href="<?php echo $post_permalink; ?>" title="<?php echo $post_title; ?>" class="rt rt-444"><?php echo $post_title; ?></a></h2>
                            <?php if (!empty($post_excerpt)) : ?>
                                <div class="desc rt rt-14 rt-overflow rt-relative rt-888">
                                    <p><?php echo $post_excerpt; ?></p>
                                </div>
                            <?php endif; ?>
                            <div class="info rt rt-13 rt-888">
                                <span class="right">
                                    <div class="num right rt-rang rt-bold rt-28"><?php echo $reading_time; ?></div>
                                    <div class="right brief rt-999 rt-op">دقیــــقه<br>مطالعه</div>
                                </span>
                                <a href="<?php echo $post_permalink; ?>" class="left rt-16 rt-z-index rt-relative rt-pointer">ادامه مقاله</a>
                            </div>
                        </div>
                        <a href="<?php echo $post_permalink; ?>" class="full-link rt rt-absolute"></a>
                    </article>
                <?php endwhile; ?>

        </div>

        <?php $pages = $wp_query->max_num_pages;
                if ($pages >= $paged) :
                    $big = 999999999; ?>
            <div class="paginate rt rt-align rt-15">
                <?php
                    echo paginate_links(array(
                        'base'    => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
                        'format'  => '/page/%#%',
                        'current' => $paged,
                        'total'   => $pages,
                        'prev_text' => 'صفحه پیشین',
                        'next_text' => 'صفحه بعد',
                        'type' => 'link',
                        'mid_size' => 5
                    ));
                ?>
            </div>
        <?php endif; ?>
    <?php endif;
            wp_reset_query(); ?>
    </div>
</section>
<?php get_footer(); ?>