<?php
/*
Template Name: وبلاگ
*/
?>
<?php get_header(); ?>
<?php if (get_theme_mod( 'charsoogh_single_blog_layout' ) == 'sidebar_none'){$blog_layout = 'col-md-12';}else{$blog_layout = 'col-md-8';} ?>
<main class="content">
            <section class="block">
                <div class="container">
                    <div class="row">
<?php if (get_theme_mod( 'charsoogh_single_blog_layout' ) == 'sidebar_right' || empty(get_theme_mod( 'charsoogh_single_blog_layout' ))){ get_sidebar(); } ?>
                        <div class="<?php echo $blog_layout; ?>">
                          <?php
                          $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
                          $posts_per_page = get_option( 'posts_per_page' );
                          $args = array( 'post_type' => 'post', 'post_status' => 'publish' , 'posts_per_page' => $posts_per_page , 'paged'  => $paged );
                          $all_posts = new WP_Query( $args );
                           ?>
                          <?php if($all_posts -> have_posts()):?>
                            <?php while($all_posts -> have_posts()): $all_posts -> the_post();?>
                            <article class="blog-post blog-archive clearfix">
                              <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                                <?php if(has_post_thumbnail()){the_post_thumbnail();} ?>
                              </a>
                              <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                                <h2><?php the_title(); ?></h2>
                              </a>
                                <div class="blog-post-content">
                                  <?php the_excerpt(); ?>
                                </div>
                                <div class="read-more-archive">
                                  <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><button class="btn btn-primary"><?php _e('Read More' , 'charsoogh'); ?></button></a>
                                </div>
                            </article>
                            <?php endwhile; endif; ?>

                            <nav class="pagination">
                            <?php
                            $total_pages = $all_posts->max_num_pages;
                                if ($total_pages > 1){
                                    $current_page = max(1, get_query_var('paged'));
                                    echo paginate_links(array(
                                        'base' => get_pagenum_link(1) . '%_%',
                                        'format' => '/page/%#%',
                                        'current' => $current_page,
                                        'total' => $total_pages,
                                    ));
                                }
                             ?>
                            </nav>
                        </div>
                        <!--end col-md-8-->
<?php if (get_theme_mod( 'charsoogh_single_blog_layout' ) == 'sidebar_left'){ get_sidebar(); } ?>
                    </div>
                </div>
                <!--end container-->
            </section>
            <!--end block-->
        </main>
<?php get_footer(); ?>
