<?php
/**
 * Home Blog Section Template
 *
 * @package Gardening Landscape Aura
 */

$gardening_landscape_aura_section_one = get_theme_mod('gardening_landscape_aura_section1_enable');
if ('Disable' == $gardening_landscape_aura_section_one) {
    return;
}

$section_title = get_theme_mod('gardening_landscape_aura_section1_title', __('From Our Gardening Blog', 'gardening-landscape-aura'));
?>

<section id="gardening-blog" class="gardening-blog-section py-5">
    <div class="container">
        <?php if ($section_title) : ?>
            <div class="section-heading-main text-center mb-5">
                <h3><?php echo esc_html($section_title); ?></h3>
            </div>
        <?php endif; ?>

        <div class="row g-4">
            <?php
            $blog_query = new WP_Query(array(
                'post_type'      => 'post',
                'posts_per_page' => 3,
                'post_status'    => 'publish',
            ));

            if ($blog_query->have_posts()) :
                while ($blog_query->have_posts()) : $blog_query->the_post();
                    ?>
                    <div class="col-lg-4 col-md-6">
                        <div class="gardening-blog-card">
                            <?php if (has_post_thumbnail()) : ?>
                                <div class="gardening-blog-img">
                                    <a href="<?php the_permalink(); ?>">
                                        <?php the_post_thumbnail('medium_large', array('class' => 'img-fluid')); ?>
                                        <div class="gardening-overlay">
                                            <span>Read More</span>
                                        </div>
                                    </a>
                                </div>
                            <?php endif; ?>

                            <div class="gardening-blog-content p-3">
                                <h4 class="gardening-blog-title">
                                    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                                </h4>
                                <p class="gardening-blog-excerpt">
                                    <?php echo wp_trim_words(get_the_excerpt(), 15, '...'); ?>
                                </p>
                                <a href="<?php the_permalink(); ?>" class="gardening-btn">Read More</a>
                            </div>
                        </div>
                    </div>
                    <?php
                endwhile;
                wp_reset_postdata();
            else :
                echo '<p class="text-center">No blog posts found.</p>';
            endif;
            ?>
        </div>
    </div>
</section>
