<?php
$food_travel_blog_options = food_travel_blog_theme_options();

$two_column_blogs_category = $food_travel_blog_options['two_column_blogs_category'];

$two_column_section_title = $food_travel_blog_options['two_column_section_title'];

$two_no_of_posts = $food_travel_blog_options['two_no_of_posts'];

?>


<div class="mid-section-sidebar section">
	<div class="container">
		<div class="row">
             <div class="col-md-12">
             <?php if ($two_column_section_title): ?>
                        <div class="section-title">
                            <?php
                            
                            if ($two_column_section_title)
                                echo '<h2>' . esc_html($two_column_section_title) . '</h2>';
                            ?>
                        </div>
                    <?php endif; ?>
             <div class="blog-list-posts">
                <?php

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

                $recent_query = new WP_Query($args);
                if ($recent_query->have_posts()){ ?>


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

                            $recent_query->the_post();
                            global $post;
                            $post_thumbnail_id = get_post_thumbnail_id(
                                get_the_ID()
                            );
                            $image = wp_get_attachment_image_src(
                                $post_thumbnail_id,
                                'food-travel-blog-blog-thumbnail-img'
                            );
                            $content = get_the_content();

                            if (!empty($image)) {
                                $image_style =
                                    "style='background-image:url(" .
                                    esc_url($image[0]) .
                                    ")'";
                            } else {
                                $image_style = '';
                            }
                            ?>
                            <div class="post-content-wrap">
                                <div class="col-md-6">
                                <a href="<?php echo esc_url(get_the_permalink()); ?>"><img src="<?php echo esc_url(
                                      $image[0]
                                  ); ?>" alt="" /></a>

                                 </div>

                                 <div class="col-md-6">
                                <div class="posts-wrap">
                                <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>

                                <h2><a href="<?php echo esc_url(
                                    get_the_permalink()
                                ); ?>"><?php the_title(); ?></a></h2>


                                  

                                 
                                  <a href="<?php echo esc_url(
                                      get_the_permalink()
                                  ); ?>" class="readmore-link"><?php esc_html_e(
    'READ MORE',
    'food-travel-blog'
); ?></a>

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

             
        </div>
    </div>
</div>
        
