<?php get_header();
$term = $wp_query->get_queried_object();
$catid = $term->term_id; ?>

<div class="chuyenmuctintuc">
    <div class="block-main">
        <div class="block-1">
            <h1>Tin tức</h1>
        </div>

        <div class="block-2">
            <div class="block-2-1">
                <?php
                
                $arg = array(
                    'post_type' => 'post',
                    'tax_query' => array(
                        array(
                            'taxonomy' => 'category',
                            'field' => 'id',
                            'terms' => $catid
                        )
                    ),
                    'paged' => get_query_var('paged'),
                );
                $news_post = new WP_Query($arg);
                if ($news_post->have_posts()):
                    $x = 1;
                    while ($news_post->have_posts()):
                        $news_post->the_post();
                        if ($x == 1) {
                            ?>
                            <div class="box-1">
                                <div class="post-1">
                                    <div class="co1">
                                        <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                                            <?php if (has_post_thumbnail())
                                                the_post_thumbnail("full", array("alt" => get_the_title()));
                                            else
                                                echo "No Image"; ?>
                                        </a>
                                    </div>
                                    <div class="co2">
                                        <h3><a class="title" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                                                <?php echo the_title(); ?>
                                            </a></h3>
                                        <?php
                                        $excerpt = get_the_excerpt();
                                        echo '<p>' . $excerpt . '</p>';
                                        ?>
                                    </div>
                                    <div class="co3">
                                        <span><i class="fa-regular fa-calendar-days" style="color: #A0AEC0;"></i>
                                            <?php the_time('d/m/Y'); ?>
                                        </span>
                                        <span><i class="fa-solid fa-user-tie" style="color: #A0AEC0;"></i>
                                            <?php the_author(); ?>
                                        </span>
                                    </div>
                                </div>
                            </div>

                            <div class="box-2">
                                <?php
                        } else {
                            if ($x == 6) {
                                echo "</div><div class='box-3'>";
                            }
                            ?>
                                <div class="post-2">
                                    <div class="post-image">
                                        <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                                            <?php if (has_post_thumbnail())
                                                the_post_thumbnail("full", array("alt" => get_the_title()));
                                            else
                                                echo "No Image"; ?>
                                        </a>
                                    </div>
                                    <div class="content">
                                        <div class="cate">
                                            <a href="<?php echo get_category_link($catid); ?>">
                                                <?php echo get_cat_name($catid); ?>
                                            </a>
                                        </div>
                                        <div class="co1">
                                            <h3><a class="title" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                                                    <?php echo the_title(); ?>
                                                </a></h3>
                                        </div>
                                        <div class="co2">
                                            <?php
                                            $excerpt = get_the_excerpt();
                                            echo '<p>' . $excerpt . '</p>';
                                            ?>
                                        </div>
                                        <div class="co3">
                                            <span1><i class="fa-regular fa-calendar-days" style="color: #A0AEC0;"></i>
                                                <?php the_time('d/m/Y'); ?>
                                            </span1>
                                            <span2><i class="fa-solid fa-user-tie" style="color: #A0AEC0;"></i>
                                                <?php the_author(); ?>
                                            </span2>
                                        </div>
                                    </div>
                                </div>
                                <?php
                        }
                        $x++;
                    endwhile;
                    wp_reset_postdata();
                    ?>
                    <?php else: ?>
                        <div class="no-posts-message">
                            <p>Không có bài viết nào được hiển thị</p>
                        </div>
                    <?php endif; ?>
                </div>

                <div class="phantrang">
                    <?php
                    flatsome_posts_pagination();
                    ?>
                </div>

            </div>

            <div class="block-2-2">
                <?php get_sidebar(); ?>
            </div>
        </div>
    </div>
</div>


<?php get_footer(); ?>