<?php 
if ( ! get_theme_mod( 'show_popular_post' ) )
    return;
$layout = get_theme_mod( 'our_post_style', 'blog-grid' );
$readmore_text = themesflat_get_opt('blog_archive_readmore_text');
if ( get_query_var('paged') ) {
    $paged = get_query_var('paged');
} elseif ( get_query_var('page') ) {
    $paged = get_query_var('page');
} else {
    $paged = 1;
}
$args_latest = array(
    'post_type' => 'post', 
    'post_status' => 'publish', 
    'posts_per_page' => 1, 
    'orderby' => 'date',
    'order' => 'desc',
    'post__not_in' => array($post->ID)
);

$args_random = array(                    
    'post_status'         => 'publish',
    'post_type'           => 'post',
    'paged' => $paged,
    'orderby'             => 'rand',
    'ignore_sticky_posts' => true,
    'posts_per_page'      => themesflat_get_opt( 'number_our_post' ),
    'post__not_in' => array($post->ID),
); 
if ( $layout != '' ) {
    $class[] = $layout;
}
global $themesflat_thumbnail;
$imgs = array(
    'blog-grid' => 'themesflat-blog-grid',
    'blog-list' => 'themesflat-blog',
    );
$themesflat_thumbnail = $imgs[$layout];

?>

<div class="our-posts">
    <div class="box-wrapper">
        <div class="our-posts-heading">
            <h3 class="box-title"><?php esc_html_e( 'Our Blogs', 'norstar' ); ?></h3>
            <a href="<?php echo esc_url(get_permalink( get_option( 'page_for_posts' ))); ?>" class="view-all-btn">
                <?php esc_html_e('View all', 'norstar') ?>
                <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
                    <g clip-path="url(#clip0_6718_7111)">
                    <path d="M5.25 4.5L12.75 12L5.25 19.5" stroke="#121212" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
                    <path d="M12.75 4.5L20.25 12L12.75 19.5" stroke="#121212" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
                    </g>
                    <defs>
                    <clipPath id="clip0_6718_7111">
                    <rect width="24" height="24" fill="white"/>
                    </clipPath>
                    </defs>
                </svg>
            </a>
        </div>
        <div class="box-content">
            <div class="row">
                <div class="col-xl-6 col-md-12 wrap-post-latest">
                    <?php 
                        $query_latest = new WP_Query($args_latest);
                        if ($query_latest->have_posts()) {
                            while($query_latest->have_posts()) : $query_latest->the_post(); ?>
                                <article <?php echo esc_attr(post_class('our-post-latest'));?>>
                                    <?php if (has_post_thumbnail()):  ?>                                    
                                        <a href="<?php the_permalink(); ?>" class="featured-post">                                            
                                                <?php  the_post_thumbnail( $themesflat_thumbnail ); ?>                                        
                                            <div class="overlay"></div>
                                        </a>
                                    <?php endif; ?>
                                    <?php render_content_post(); ?>
                                </article>
                            <?php endwhile; ?>
                            <?php wp_reset_postdata(); ?>
                        <?php } ?>
                </div>
                <div class="col-xl-6 col-md-12 our-post-random">
                    <?php 
                        $query_random = new WP_Query($args_random);
                        if ($query_random->have_posts()) { ?>
                            <div class="wrap-random-post">
                                <?php while ($query_random->have_posts()) : $query_random->the_post(); ?>
                                    <article <?php echo esc_attr(post_class('entry post-random-item')); ?>>
                                        <?php if ( has_post_thumbnail() ): ?>
                                           <div class="our-post-thumbnail">
                                                <a href="<?php the_permalink();?>"><?php the_post_thumbnail(array(312, 312), array('class' => 'thumbnail', 'alt' => '')); ?></a>
                                                <div class="content-post-rand-overlay"></div>
                                           </div>   
                                        <?php endif; ?>                                        
                                           <?php render_content_post(); ?>                                                                                   
                                    </article>
                                <?php endwhile; ?>
                                <?php wp_reset_postdata(); ?>
                            </div>
                        <?php } ?>
                </div>
            </div>
        </div>
    </div>
</div>