<?php

/**
 * The template for displaying archive pages
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package Glowify WP
 */

	$enable_archive_bg = glowify_wp_option('enable_archive_bg');

	$blog_archive_bc_bg = glowify_wp_option('blog_archive_bc_bg');

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


	$blog_archive_layout = glowify_wp_option('blog_archive_layout');

	if(!empty($blog_archive_layout)){
		$blog_archive_layout = glowify_wp_option('blog_archive_layout');
	}else{
		$blog_archive_layout = 'right-sidebar';
	}

	if(!empty($blog_archive_layout) && $blog_archive_layout != 'full-width' && is_active_sidebar( 'glowify-blog-archive-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';
	}

	if(have_posts()){
		$blog_row_resize = 'grid';
	} else {
		$blog_row_resize = 'no-grid';
	}
	

get_header();

?>

<?php if ($enable_archive_bg == 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_archive_bc_src) && is_array($blog_archive_bc_src) && !empty($blog_archive_bc_src[0])) : ?>
        data-src="<?php echo esc_url($blog_archive_bc_src[0]); ?>"
        <?php endif; ?>>
      
        <div>
			<?php
				the_archive_title( '<h1 class="cs_breadcamp_title cs_fs_54 cs_semibold">', '</h1>' );
				the_archive_description( '<div class="archive-description">', '</div>' );
			?>
          <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 single_cat_title(); ?>
            </li>
          </ol>
        </div>
      </div>
    </div>
    <?php endif; ?>



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

				<div class="<?php echo esc_attr($main_col_class)?> <?php echo esc_attr($blog_archive_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() ) : ?>

								<?php
									/* 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', 'archive' );
									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_archive_layout == 'right-sidebar'  && is_active_sidebar('glowify-blog-archive-sidebar') ) :?>
					<?php if(is_active_sidebar('glowify-blog-archive-sidebar')) : ?>
						<div class="col-lg-4 col-12">
							<aside class="sidebar-main"> 
								<?php dynamic_sidebar('glowify-blog-archive-sidebar'); ?>
							</aside>
						</div>
					<?php endif; ?>	
				<?php endif; ?>
			</div>
		</div>
	</div>

<?php

get_footer();