<?php
/**
 * The main template file
 *
 * This is the most generic template file in a WordPress theme
 * and one of the two required files for a theme (the other being style.css).
 * It is used to display a page when nothing more specific matches a query.
 * E.g., it puts together the home page when no home.php file exists.
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package Glowify WP
 */

$enable_blog_bc = glowify_wp_option('enable_blog_bc');
$blog_bc_custom_title = glowify_wp_option('blog_bc_custom_title');
$blog_main_bc_bg = glowify_wp_option('blog_main_bc_bg');

if ($blog_main_bc_bg) {
    $blog_main_bc_bg_src = wp_get_attachment_image_src($blog_main_bc_bg['id'], 'full', false);
}

$blog_page_layout = glowify_wp_option('blog_page_layout') ?: 'right-sidebar';

if (!empty($blog_page_layout) && $blog_page_layout != 'full-width' && is_active_sidebar('glowify-blog-sidebar')) {
    $main_col_class = 'col-lg-8 col-12';
} else {
    $main_col_class = 'col-lg-10 offset-lg-1 col-md-10 offset-md-1 col-12';
}

$blog_row_resize = have_posts() ? 'grid' : 'no-grid';

get_header();
?>

    <?php if ($enable_blog_bc == true) : ?>
    <div class="cs_height_40 cs_height_lg_30"></div>
    <div class="container">
      <div class="cs_breadcamp_wrap cs_style_1 cs_accent_light_bg cs_bg_filed cs_radius_8" 
        <?php if (!empty($blog_main_bc_bg_src) && is_array($blog_main_bc_bg_src) && !empty($blog_main_bc_bg_src[0])) : ?>
        data-src="<?php echo esc_url($blog_main_bc_bg_src[0]); ?>"
        <?php endif; ?>>
      
        <div>
          <h1 class="cs_breadcamp_title cs_fs_54 cs_semibold">
            <?php if (!empty($blog_bc_custom_title)) { 
                echo esc_html($blog_bc_custom_title); 
            } else { 
                echo esc_html__('Blog Posts', 'glowify-wp');
            } ?>
          </h1>
          <ol class="breadcrumb cs_fs_18 mb-0">
            <li class="breadcrumb-item"><a href="<?php echo esc_url(home_url('/')); ?>"><?php esc_html_e('Home','glowify-wp');?></a></li>
            <li class="breadcrumb-item active">
                <?php 
                if (!empty($blog_bc_custom_title)) { 
                    echo esc_html($blog_bc_custom_title); 
                } else { 
                    esc_html_e('Blog', 'glowify-wp'); 
                } 
                ?>
            </li>
          </ol>
        </div>
      </div>
    </div>
    <?php endif; ?>

    <div class="glowify-internal-area glowify-blog-main-section glowify-blog-area glowify-blog-archive <?php echo esc_attr( $blog_page_layout); ?>">
        <div class="container">
            <div class="row">
                
                <?php if ($blog_page_layout == 'left-sidebar' && is_active_sidebar('glowify-blog-sidebar') ) :?>
                    <div class="col-lg-4 col-12">
                        <aside id="secondary" class="sidebar-main cs_left_sidebar">
                            <?php get_sidebar();?>
                        </aside>
                    </div>
                <?php endif;?>

                <div class="<?php echo esc_attr($main_col_class) ?> <?php echo esc_attr($blog_page_layout) ?>">
                    <div class="blog-main-layout glowify-blog-main-section__archive">
                        <div class="row <?php echo esc_attr($blog_row_resize); ?>">
                            <?php
                            if (have_posts()) :
                                if (is_home() && !is_front_page()) :
                                    ?>
                                    <header>
                                        <h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
                                    </header>
                                    <?php
                                endif;

                                /* Start the Loop */
                                while (have_posts()) :
                                    the_post();

                                    /*
                                    * Include the Post-Type-specific template for the content.
                                    * If you want to override this in a child theme, then include a file
                                    * called content-___.php (where ___ is the Post Type name) and that will be used instead.
                                    */
                                    get_template_part('template-parts/content', get_post_type());

                                endwhile;
                            else :
                                get_template_part('template-parts/content', 'none');
                            endif;
                            ?>
                        </div>

                        <div class="row">
                            <div class="col-12">
                                <?php if (function_exists('glowify_wp_pagination')) : ?>
                                    <div class="pagination-main">
                                        <?php glowify_wp_pagination(); ?>
                                    </div>
                                <?php endif; ?>
                            </div>
                        </div>
                    </div>
                </div>


                <?php if ($blog_page_layout == 'right-sidebar' && is_active_sidebar('glowify-blog-sidebar') ) :?>
                    <div class="col-lg-4 col-12">
                        <aside id="secondary" class="sidebar-main cs_right_sidebar">
                            <?php  get_sidebar();?>
                        </aside>
                    </div>
                <?php endif;?>

            </div>
        </div>
    </div>

<?php
get_footer();
?>
