<?php
/** Template Name: Blog Template */
get_header();

// Open layout
require( OVA_THEME_URL.'/templates/ova_open_layout.php' ); ?>


<?php 
    $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    $args = array(    
        'paged' => $paged,
        'post_type' => 'post',
        'orderby'   => 'date',
    );
    $blog = new WP_Query($args);

    if ( $blog->have_posts() ) : while ( $blog->have_posts() ) : $blog->the_post(); ?>
        <?php get_template_part( 'content/content', get_post_format() ); ?>
    <?php endwhile; ?>
            <div class="pagination-wrapper text-center">
                <?php
                    global $wp_query;

                    $big = 999999999; // need an unlikely integer
                    $pages = paginate_links(array(
                                 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
                                 'format' => '?paged=%#%',
                                 'current' => max(1, get_query_var('paged') ),
                                 'total' => $blog->max_num_pages,
                                 'next_text'    => wp_kses( __('<i class="fa fa-chevron-right"></i>', 'helium'), true),
                                 'prev_text'    => wp_kses( __('<i class="fa fa-chevron-left"></i>', 'helium'), true),
                                 'type'         => 'array',
                             ) );

                    if( is_array( $pages ) ) {
                        $paged = ( get_query_var('paged') == 0 ) ? 1 : get_query_var('paged');
                        echo wp_kses( __('<ul class="pagination">', 'helium'), true);
                        foreach ( $pages as $page ) {
                                echo wp_kses( __('<li>', 'helium'), true) .wp_kses($page,true). wp_kses( __('</li>', 'helium'), true);
                        }
                       echo wp_kses( __('</ul>', 'helium'), true ) ;
                    }
                ?>
            </div>
    <?php else : ?>
            <p><?php esc_html_e('Sorry, no pages matched your criteria.', 'helium'); ?></p>
    <?php endif; wp_reset_postdata(); ?>
<?php
// Close layout
require( OVA_THEME_URL.'/templates/ova_close_layout.php' );?>

<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
    the_content();
    wp_link_pages();
    endwhile; ?>
<?php endif;?>

<?php 
    get_footer();
?>