<?php

    if ( minimalista_base_setting('minimalista_base_enable_recent_posts', true) == true ) :

        $args = array(
            'post_type' => 'post',
            'posts_per_page' => 5,
            'ignore_sticky_posts' => true,
        );
        
        $recent_posts = new WP_Query($args);
        $recent_posts_enabled = minimalista_base_setting('minimalista_base_enable_recent_posts_only_first_page_pagination', false);
    
        if (
            $recent_posts->have_posts() &&
            (
                (
                    $recent_posts_enabled == true && 
                    get_query_var('paged') <= 1
                ) ||
                $recent_posts_enabled == false
            )
    
        ) :

    ?>

        <section class="recent-posts-section">

            <div class="container">
                
                <div class="row">
                    
                    <div class="col-md-12">

                        <div class="recent-posts-grid">

                            <div class="recent-posts-left-column">
                                
                                <?php

                                    while ($recent_posts->have_posts()) : $recent_posts->the_post();
                                        
                                        global $post;

                                        $post_count = $recent_posts->current_post + 1;

                                        if ($post_count <= 2) :
                                
                                ?>

                                            <div class="recent-post">

                                                <?php

                                                    if ('' != get_the_post_thumbnail() ) : 

                                                        the_post_thumbnail('minimalista_base_recent_post_medium');
                                                    
                                                    else :

                                                        $thumbnailIMG = get_stylesheet_directory_uri() . '/assets/images/placeholder-650x439.jpg';
                                                        echo '<img src="' . esc_url($thumbnailIMG) . '" alt="' . esc_attr(get_the_title()) . '">';
                                    
                                                    endif;
                                                ?>

                                                <p class="category"><?php the_category(' . ');?></p>
                                                <h2><a href="<?php echo esc_url(get_permalink()); ?>"><?php echo esc_html(get_the_title()); ?></a></h2>
                                                <p class="author"><?php echo esc_html__('Written by ','minimalista-base') . get_the_author_posts_link(); ?></p>

                                            </div>
                                <?php

                                        endif;
                                        if ($post_count == 3) :
                                
                                ?>

                            </div>

                            <div class="recent-posts-center-column">

                                <?php

                                    if ('' != get_the_post_thumbnail() ) : 

                                        the_post_thumbnail('minimalista_base_recent_post_large');
                                    
                                    else :

                                        $thumbnailIMG = get_stylesheet_directory_uri() . '/assets/images/placeholder-700x490.jpg';
                                        echo '<img src="' . esc_url($thumbnailIMG) . '" alt="' . esc_attr(get_the_title()) . '">';
                    
                                    endif;
                                ?>
                                
                                <div class="recent-posts-article-content">

                                    <p class="category"><?php the_category(' . ');?></p>
                                    <h2><a href="<?php echo esc_url(get_permalink()); ?>"><?php echo esc_html(get_the_title()); ?></a></h2>
                                    <p class="author"><?php echo esc_html__('Written by ','minimalista-base') . get_the_author_posts_link(); ?></p>
                                    <p class="description"><?php echo the_excerpt(); ?></p>

                                </div>

                            </div>

                            <div class="recent-posts-right-column">
                                
                                <?php
                                
                                    endif;
                                    if ($post_count > 3) :
                                
                                ?>

                                        <div class="recent-post">

                                            <?php

                                                if ('' != get_the_post_thumbnail() ) : 

                                                    the_post_thumbnail('minimalista_base_recent_post_medium');
                                                
                                                else :

                                                    $thumbnailIMG = get_stylesheet_directory_uri() . '/assets/images/placeholder-650x439.jpg';
                                                    echo '<img src="' . esc_url($thumbnailIMG) . '" alt="' . esc_attr(get_the_title()) . '">';
                                
                                                endif;
                                            ?>

                                            <p class="category"><?php the_category(' . ');?></p>
                                            <h2><a href="<?php echo esc_url(get_permalink()); ?>"><?php echo esc_html(get_the_title()); ?></a></h2>
                                            <p class="author"><?php echo esc_html__('Written by ','minimalista-base') . get_the_author_posts_link(); ?></p>

                                        </div>

                            <?php

                                    endif;

                                endwhile;
                                wp_reset_postdata();
                                
                            ?>

                            </div>

                        </div>

                    </div>

                </div>

            </div>

        </section>

<?php

        endif;


    endif;

?>