<?php /* Template Name: Careers Page */ ?>
<?php get_header(); ?>
 <!-- Start Breadcrumb 
    ============================================= -->
    <div class="breadcrumb-area text-center shadow dark bg-fixed text-light" style="background-image: url(<?php echo get_field('web_banner'); ?>);">
        <div class="container">
            <div class="row">
                <div class="col-lg-8 offset-lg-2">
                    <h1><?php echo get_field('banner_title'); ?></h1>
                    <ul class="breadcrumb">
                        <li><a href="<?php echo site_url() ?>"><i class="fas fa-home"></i> Home</a></li>
                        <li class="active">Careers</li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
    <!-- End Breadcrumb -->

    <!-- Start Blog
    ============================================= -->
    <div class="blog-area full-blog blog-standard full-blog grid-colum default-padding">
        <div class="container">
            <div class="blog-items">
                <div class="blog-content">
                    <div class="blog-item-box">
                    <?php
                    // Get the current page number
                    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

                    // Arguments for the WP_Query
                    $args = array(
                        'post_type' => 'career', // Custom post type
                        'posts_per_page' => 6,   // Number of items per page
                        'paged' => $paged,       // For pagination
                        'orderby' => 'meta_value', // Order by custom field or 'date' for default
                        'meta_key' => 'closing_date', // If ordering by custom field, replace 'career_date' with the field name
                        'order' => 'DESC',        // ASC or DESC
                    );

                    // The Query
                    $query = new WP_Query($args);

                    // The Loop
                    if ($query->have_posts()) : ?>
                        <div class="row">
                            <?php while ($query->have_posts()) : $query->the_post(); ?>
                                <div class="col-lg-4 col-md-6 single-item">
                                    <div class="item wow fadeInUp" data-wow-delay="500ms">
                                        <div class="thumb">
                                            <?php if (has_post_thumbnail()) : ?>
                                                <img src="<?php the_post_thumbnail_url(); ?>" alt="<?php the_title(); ?>">
                                            <?php endif; ?>
                                            <div class="date">
                                                <?php echo get_field('closing_date'); ?>
                                            </div>
                                        </div>
                                        <div class="info">
                                            <h4>
                                                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                                            </h4>
                                            <a class="btn circle btn-gray border btn-md" href="<?php the_permalink(); ?>">Apply Now</a>
                                        </div>
                                    </div>
                                </div>
                            <?php endwhile; ?>
                        </div>

                        <!-- Pagination -->
                        <div class="row">
                            <div class="col-md-12 pagi-area text-center">
                                <nav aria-label="navigation">
                                    <?php
                                    // Pagination Links
                                    echo paginate_links(array(
                                        'total' => $query->max_num_pages,
                                        'current' => $paged,
                                        'prev_text' => '<i class="fas fa-angle-double-left"></i>',
                                        'next_text' => '<i class="fas fa-angle-double-right"></i>',
                                    ));
                                    ?>
                                </nav>
                            </div>
                        </div>
                    <?php
                    else :
                        echo '<p>No careers found</p>';
                    endif;

                    // Restore original Post Data
                    wp_reset_postdata();
                    ?>

                        


                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- End Blog -->

<?php get_footer(); ?>