<?php
$food_travel_blog_options = food_travel_blog_theme_options();
$green_blog_carousel = $food_travel_blog_options['green_blog_carousel'];
$green_blog_section_title = $food_travel_blog_options['green_blog_section_title'];
?>

<?php
if ($green_blog_carousel && 'none' != $green_blog_carousel) {
    $args = [
        'post_type' => 'post',
        'posts_per_page' => 4,
        'post_status' => 'publish',
        'order' => 'desc',
        'orderby' => 'menu_order date',
        'tax_query' => [
            'relation' => 'AND',
            [
                'taxonomy' => 'category',
                'field' => 'slug',
                'terms' => [$green_blog_carousel],
            ],
        ],
    ];
} else {
    $args = [
        'post_type' => 'post',
        'posts_per_page' => 4,
        'post_status' => 'publish',
        'order' => 'desc',
        'orderby' => 'menu_order date',
    ];
}

$blog_query = new WP_Query($args);
$loop = 0;

if ($blog_query->have_posts()): ?>




<div class="blog-carousel-section section bottom-carousel">
<div class="container">
        <div class="row">
         <?php
                            
                             if ($green_blog_section_title): ?>

                        <div class="section-title">
                           
                            <?php    echo '<h2>' . esc_html($green_blog_section_title) . '</h2>'; ?>
                          
                        
                        </div>
                  <?php   endif; ?>
                   
                </div>
        </div>


			<div class="card-grid-wrap threecolumn">

            <?php
            while ($blog_query->have_posts()):

                $blog_query->the_post();

                    $image_src = wp_get_attachment_image_src(
                        get_post_thumbnail_id(),
                        'food-travel-blog-custom-size'
                    );

                if($image_src){
                    $url = $image_src[0];
                    }
                ?>

				<div class="card-wraps">
					<div class="card-content-wrap">
						<div class="carousel-thumb">
                        
                        <a href="<?php echo esc_url(get_the_permalink()); ?>"><img src="<?php echo esc_url($url); ?>"></a>
						</div>
						<div class="post-content">
                        <ul class="post-meta">
                            <li class="meta-date"><a href="<?php echo esc_url(
                                food_travel_blog_archive_link($post)
                                                            ); ?>"><time class="entry-date published" datetime="<?php echo esc_url(
                                    food_travel_blog_archive_link($post)
                                ); ?>"><?php echo esc_html(the_time(get_option('date_format'))); ?></time>
                                                                                </a></li>
                                </ul>
							<h3>
								<a href="<?php echo esc_url(get_the_permalink()); ?>"><?php the_title(); ?></a>
							</h3>
							
						</div>
					</div>
				</div>

                <?php
            endwhile;
            wp_reset_postdata();
            ?>
	</div>
</div>

<?php endif;
?>

