<?php
/**
 * Latest Posts
 *
 * @package NewsNation
 */
if( !function_exists('newsnation_latest_blocks') ):
    
    function newsnation_latest_blocks($newsnation_home_section,$repeat_times){

        global $post;
        $newsnation_default = newsnation_get_default_theme_options();
        $sidebar = esc_attr( get_theme_mod( 'global_sidebar_layout', $newsnation_default['global_sidebar_layout'] ) );

        $newsnation_archive_layout = esc_attr( get_theme_mod( 'newsnation_archive_layout', $newsnation_default['newsnation_archive_layout'] ) ); ?>
        <div id="theme-block-<?php echo esc_attr( $repeat_times ); ?>" class="theme-block theme-block-archive">
            <div class="wrapper">
                <div id="primary" class="content-area theme-bottom-sticky">
                    <main id="main" class="site-main" role="main">

                            <?php
                            if( !is_front_page() && !is_home()  ) {
                                newsnation_breadcrumb_with_title_block();
                            }

                            if( have_posts() ): ?>

                                <div class="article-wraper archive-layout <?php echo 'archive-layout-' . esc_attr( $newsnation_archive_layout ); ?>">
                                    <?php while (have_posts()) :
                                        the_post();

                                        if( !is_page() ){

                                            get_template_part( 'template-parts/content', get_post_format() );

                                        }else{
                                            get_template_part('template-parts/content', 'single');
                                        }


                                    endwhile; ?>
                                </div>

                                <?php if( !is_page() ): do_action('newsnation_archive_pagination'); endif;

                            else :

                                get_template_part('template-parts/content', 'none');

                            endif; ?>

                    </main><!-- #main -->
                </div>

                <?php if( $sidebar != 'no-sidebar' ){

                    get_sidebar();

                } ?>
            </div>
        </div>

    <?php
    }
    
endif;
