<?php
$enable_article_grid_section = blogaura_get_option('enable_article_grid_section');
$article_grid_post_title_1 = blogaura_get_option('article_grid_post_title_1');
$article_grid_post_category = blogaura_get_option('article_grid_post_category');
$enable_article_grid_author_meta = blogaura_get_option('enable_article_grid_author_meta');
$select_article_grid_author_meta = blogaura_get_option('select_article_grid_author_meta');
$article_grid_author_meta_title = blogaura_get_option('article_grid_author_meta_title');
$enable_article_grid_date_meta = blogaura_get_option('enable_article_grid_date_meta');
$select_article_grid_date = blogaura_get_option('select_article_grid_date');
$select_article_grid_date_meta_title = blogaura_get_option('select_article_grid_date_meta_title');
$select_article_grid_date_format = blogaura_get_option('select_article_grid_date_format');
$enable_article_grid_category_meta = blogaura_get_option('enable_article_grid_category_meta');
$article_grid_category_label = blogaura_get_option('article_grid_category_label');
$select_article_grid_category_color = blogaura_get_option('select_article_grid_category_color');
$select_article_grid_number_of_category = blogaura_get_option('select_article_grid_number_of_category');
if (empty($enable_article_grid_section)) {
    return;
}
?>
<section class="wpi-section theme-article-grid">
    <div class="wrapper">
        <?php if ($article_grid_post_title_1) { ?>
            <header class="wpi-section-header">
                <h2 class="section-header-title"><?php echo esc_html($article_grid_post_title_1); ?></h2>
            </header>
        <?php } ?>
        <div class="article-grid-content">
            <?php
            $article_grid_args_1 = array(
                'post_type' => 'post',
                'posts_per_page' => 6,
                'post_status' => 'publish',
                'no_found_rows' => 1,
                'ignore_sticky_posts' => 1,
            );
            // Check for category.
            if (!empty($article_grid_post_category)) :
                $article_grid_args_1['tax_query'] = array(
                    array(
                        'taxonomy' => 'category',
                        'field' => 'term_id',
                        'terms' => $article_grid_post_category,
                    ),
                );
            endif;
            $article_grid_post_1 = new WP_Query($article_grid_args_1);
            if ($article_grid_post_1->have_posts()) :
                $delay = 100;
                while ($article_grid_post_1->have_posts()) :
                    $article_grid_post_1->the_post(); ?>
                    <article id="article-grid-block-<?php the_ID(); ?>" class="wpi-post wpi-post-list" data-aos="fade-up" data-aos-duration="1000"
                             data-aos-delay="<?php echo esc_attr($delay); ?>">
                        <?php if (has_post_thumbnail()) : ?>
                            <div class="entry-image entry-image-thumbnail image-hover-effect hover-effect-zoom">
                                <a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true"
                                   tabindex="-1">
                                    <?php
                                    the_post_thumbnail(
                                        'medium',
                                        array(
                                            'alt' => the_title_attribute(
                                                array(
                                                    'echo' => false,
                                                )
                                            ),
                                        )
                                    );
                                    ?>
                                </a>
                            </div>
                        <?php endif; ?>
                        <div class="entry-details">
                            <?php
                            if ($enable_article_grid_category_meta) {
                                blogaura_post_category($select_article_grid_category_color, $article_grid_category_label, $select_article_grid_number_of_category);
                            }
                            ?>
                            <h3 class="entry-title entry-title-xsmall limit-line-3">
                                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                            </h3>
                            <div class="entry-meta-wrapper">
                                <?php
                                if ($enable_article_grid_date_meta) {
                                    blogaura_posted_on($select_article_grid_date_format, $select_article_grid_date_meta_title, $select_article_grid_date);
                                }
                                ?>
                                <?php
                                if ($enable_article_grid_author_meta) {
                                    blogaura_posted_by($select_article_grid_author_meta, $article_grid_author_meta_title);
                                }
                                ?>
                            </div>
                        </div>
                    </article>
                <?php
                    $delay += 100;
                endwhile;
                wp_reset_postdata();
            endif; ?>
        </div>
            
    </div>
</section>