<!-- Related Programs -->
<?php
$current_post_id = get_the_ID();

// Get the latest 4 pages under the 'hads-programs' category excluding the current one
$news_args = array(
    'post_type' => 'page',
    'posts_per_page' => 4,
    'category_name' => 'hads-programs',
    'post__not_in' => array($current_post_id) // Exclude the current post
);

$news_query = new WP_Query($news_args);

if ($news_query->have_posts()) :
?>
<div class="row">
    <?php while ($news_query->have_posts()) : $news_query->the_post(); ?>
    <div class="col-md-3 col-sm-6 h-100">
        <article>
            <a href="<?= esc_url(get_permalink()); ?>">
                <div class="card shadow-sm border-0" data-aos="fade-up">
                    <div class="post-thumbnail">
                        <?php // Display the post thumbnail
                        if (has_post_thumbnail()) {
                            the_post_thumbnail('full', ['class' => 'img-fluid']);
                        } else {
                            echo '<img src="' . get_template_directory_uri() . '/assets/images/placeholder-image.jpg" alt="HADS" class="img-fluid"/>';
                        }
                        ?>
                    </div>
                    <div class="card-body">
                        <h5><?php the_title(); ?></h5>
                        <a href="<?= esc_url(get_permalink()); ?>" class="btn btn-outline-info read-more">Read More</a>
                    </div><!-- card body -->
                </div><!-- card -->
            </a>
        </article>
    </div><!-- col -->
    <?php endwhile;
    wp_reset_postdata();
    ?>
</div><!-- row -->
<?php
else :
    echo 'No related programs.';
endif;
?>
