<?php
/**
 * Template Name: Blog Template
 *
 * @package WordPress
 */
__('Blog Template', TEXT_DOMAIN);

$featuredQueryArgs = array(
    'post_type' => 'post',
    'post_status' => 'publish',
    'posts_per_page' => '8',
    'meta_query' => array(
        array(
            'key' => TEXT_DOMAIN . '_featured',
            'value' => 'on'
        )
    )
);
$featuredQuery = new \WP_Query($featuredQueryArgs);
$columns = get_option(TEXT_DOMAIN . '_blog_columns','col-lg-3');
get_header(); ?>
    <main>
        <div class="mt-4 mb-5">
            <div class="custom-container">
                <!-- breadcrumb -->
                <?php banta_breadcrumb(); ?>

                <!-- featured posts -->
                <div class="swiper featured-posts-swiper mt-3 mb-5">
                    <div class="swiper-wrapper">
                        <?php if ($featuredQuery->have_posts()): ?>
                            <?php while ($featuredQuery->have_posts()): $featuredQuery->the_post(); ?>
                                <div class="swiper-slide">
                                    <div class="featured-post-item">
                                        <?php if (has_post_thumbnail()): the_post_thumbnail('full-size');
                                        else:
                                            echo "<img src='" . esc_url(get_template_directory_uri() . '/images/default.jpg') . "' alt='image'>";
                                        endif; ?>

                                        <div class="featured-post-item-overly">
                                            <div class="d-flex flex-column">
                                                <a href="<?php the_permalink() ?>"
                                                   class="title"><?php the_title(); ?></a>
                                                <div class="d-flex mt-3">
                                                    <?php
                                                    $category = get_the_category();
                                                    $firstCategory = $category[0];
                                                    ?>
                                                    <div class="post-meta-item"><i class="icon-tag"></i><a
                                                                href="<?php echo get_term_link($firstCategory); ?>"
                                                                class="ms-2"><?php echo $firstCategory->cat_name ?></a></div>
                                                    <div class="post-meta-item"><i class="icon-calendar"></i><span
                                                                class="ms-2"><?php banta_date('j F Y', get_the_date('y-m-d')); ?></span>
                                                    </div>
                                                </div>
                                            </div>
                                            <a href="<?php the_permalink() ?>" class="more">
                                                <span class="me-2 more-title"><?php echo _e('Read More', TEXT_DOMAIN); ?></span>
                                                <span class="iconlyBulk-Arrow-Left font-20"><span
                                                            class="path1"></span><span class="path2"></span></span>
                                            </a>
                                        </div>
                                    </div>
                                </div>
                                <?php wp_reset_postdata(); endwhile; ?>
                        <?php endif; ?>
                    </div>
                    <?php if($featuredQuery->found_posts > 1):?>
                    <div class="custom-swiper-button-prev"><i class="iconly-Arrow-Right"></i></div>
                    <div class="custom-swiper-button-next"><i class="iconly-Arrow-Left"></i></div>
                    <?php endif;?>
                </div>

                <!-- page title -->
                <div class="section-head mb-5">
                    <div class="d-flex align-items-end flex-shrink-0">
                        <div class="title"><?php the_title();?></div>
                    </div>
                    <div class="horizontal-head-line"></div>
                </div>

                <!-- post items -->
                <div class="row">
                    <?php query_posts('post_type=post&post_status=publish&paged=' . get_query_var('paged'));
                    if (have_posts()):?><?php while (have_posts()): the_post(); ?>
                        <div class="<?php echo $columns?> col-sm-6 mb-4">
                            <?php include(TEMPLATEPATH."/inc/loop/post-item.php");?>
                        </div>
                        <?php wp_reset_postdata(); endwhile; ?>
                    <?php endif; ?>
                </div>

                <div class="mt-5 mb-5">
                    <!-- pagination -->
                    <div class="bcp-pagination">
                        <?php banta_posts_navigation();?>
                    </div>
                </div>
            </div>
        </div>

    </main>
<?php get_footer(); ?>