<?php
$food_travel_blog_options = food_travel_blog_theme_options();
$grid_layout_blog_category = $food_travel_blog_options['grid_layout_blog_category'];
$grid_layout_section_title = $food_travel_blog_options['grid_layout_section_title'];
$three_no_of_posts = $food_travel_blog_options['three_no_of_posts'];
$grid_layout = $food_travel_blog_options['grid_layout'];
?>

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

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

if ($blog_query->have_posts()): 



if($grid_layout==3){ ?>
    <div class="blog-grid-section section" id="primary">
<?php } 
else { ?>
    <div class="blog-grid-section four-column section">
    
<?php } ?>


    <div class="container">
        <div class="row">
        <?php if ($grid_layout_section_title): ?>
                        <div class="section-title">
                            <?php
                            
                            
                                echo '<h2>' . esc_html($grid_layout_section_title) . '</h2>'; ?>
                          
                           
                        </div>

                    <?php endif; ?>
                   
                </div>
        </div>
    
	<div class="container">
		<div class="row">
			<div class="card-grid-wrap threecolumns">

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

                $blog_query->the_post();

                    $image_src = wp_get_attachment_image_src(
                        get_post_thumbnail_id(),
                        'food-travel-blog-blog-thumbnail-img'
                    );

                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>
	</div>
</div>

<?php endif;
?>

