<?php
/**
 * The template for displaying all single posts
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/#single-post
 *
 * @package Glowify wp
 */

$display_post_nav = glowify_wp_option('display_post_nav');

if (get_post_meta($post->ID, 'glowify_wp_breadcrumb_options', true)) {
    $page_meta = get_post_meta($post->ID, 'glowify_wp_breadcrumb_options', true);
} else {
    $page_meta = array();
}

if (array_key_exists('enable_breadcrumb', $page_meta)) {
    $enable_breadcrumb = $page_meta['enable_breadcrumb'];
} else {
    $enable_breadcrumb = false;
}

// Breadcrumb Background
if (array_key_exists('bc_page_background', $page_meta)) {
    $bc_page_background = $page_meta['bc_page_background'];
} else {
    $bc_page_background = false;
}
if ($bc_page_background) {
    $bc_page_background_src = wp_get_attachment_image_src($bc_page_background['id'], 'full', false);
}
if (array_key_exists('bc_custom_title', $page_meta)) {
    $bc_custom_title = $page_meta['bc_custom_title'];
} else {
    $bc_custom_title = '';
}

// Post Layout Meta
if (get_post_meta($post->ID, 'glowify_wp_blog_options', true)) {
    $glowify_wp_blog_options = get_post_meta($post->ID, 'glowify_wp_blog_options', true);
} else {
    $glowify_wp_blog_options = array();
}

$post_default_layout = glowify_wp_option('post_default_layout');

if (array_key_exists('post_layout', $glowify_wp_blog_options) && $glowify_wp_blog_options['post_layout'] != '1') {
    $post_layout = $glowify_wp_blog_options['post_layout'];
} elseif (!empty($post_default_layout)) {
    $post_layout = glowify_wp_option('post_default_layout');
} else {
    $post_layout = 'right-sidebar';
}

if (!empty($post_layout) && $post_layout != 'full-width' && is_active_sidebar('glowify-blog-single-sidebar')) {
    $single_post_column = 'col-xxl-8 col-lg-8 col-12';
} else {
    $single_post_column = 'col-lg-10 offset-lg-1 col-12';
}

get_header();
?>


    <?php if ($enable_breadcrumb == 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($bc_page_background_src)) : ?>
      data-src="<?php echo esc_url($bc_page_background_src[0]); ?>" 
      
      style="background-image: url(<?php echo esc_url($bc_page_background_src[0]); ?>);"
      <?php endif;?>>
        <div>
          <h1 class="cs_breadcamp_title cs_fs_54 cs_semibold">
            <?php if (!empty($bc_custom_title)) { 
                echo esc_html($bc_custom_title); 
            } else { 
                the_title(); 
            } ?>
          </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 the_title(); ?></li>
          </ol>
        </div>
      </div>
    </div>
    <?php endif; ?>


<section class="glowify-blog-main-section blog-single section-padding glowify-blog-area <?php echo esc_attr($post_layout); ?>">
    


    <div class="glowify-inner-post-area">
        <div class="container">

            <div class="cs_height_40 cs_height_lg_30"></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>
                <?php
                $categories = get_the_category();
                if (!empty($categories)) {
                    $category = $categories[0]; // Get the first category
                    $category_link = get_category_link($category->term_id);
                    $category_name = $category->name;
                    echo '<li class="breadcrumb-item"><a href="' . esc_url($category_link) . '">' . esc_html($category_name) . '</a></li>';
                }
                ?>
                <li class="breadcrumb-item active"><?php the_title(); ?></li>
            </ol>

            <div class="cs_height_30 cs_height_lg_30"></div>
            
            <div class="row cs_gap_y_40">
                <?php if (function_exists('glowify_wp_option') && $post_layout == 'left-sidebar') : ?>
                    <?php if (is_active_sidebar('glowify-blog-single-sidebar')) : ?>
                        <div class="col-xxl-4 col-lg-4 col-12">
                            <aside class="sidebar-main cs_right_sidebar mt-0">
                                <?php dynamic_sidebar('glowify-blog-single-sidebar'); ?>
                            </aside>
                        </div>
                    <?php endif; ?>
                <?php endif; ?>
                <?php if (function_exists('glowify_wp_option')) : ?>
                    <div class="<?php echo esc_attr($single_post_column); ?>">
                <?php elseif (!function_exists('glowify_wp_option') && is_active_sidebar('glowify-blog-single-sidebar')) : ?>
                    <div class="col-lg-8 col-12">
                <?php else : ?>
                    <div class="col-lg-10 offset-lg-1 col-md-10 offset-md-1 col-12">
                <?php endif; ?>
                    <div class="row">
                        <div class="col-12">
                            <?php
                            while (have_posts()) :
                                the_post();
                                get_template_part('template-parts/content', 'single');
                                if (comments_open() || get_comments_number()) :
                                    comments_template();
                                endif;
                            endwhile; // End of the loop.
                            ?>
                        </div>
                    </div>
                </div>
                <?php if (function_exists('glowify_wp_option') && $post_layout == 'right-sidebar') : ?>
                    <?php if (is_active_sidebar('glowify-blog-single-sidebar')) : ?>
                        <div class="col-xxl-4 col-lg-4 col-12">
                            <aside class="sidebar-main cs_left_sidebar mt-0">
                                <?php dynamic_sidebar('glowify-blog-single-sidebar'); ?>
                            </aside>
                        </div>
                    <?php endif; ?>
                <?php endif; ?>
                <?php if (!function_exists('glowify_wp_option')) : ?>
                    <?php if (is_active_sidebar('glowify-blog-single-sidebar')) : ?>
                        <div class="col-lg-4 col-12">
                            <aside class="sidebar-main cs_left_sidebar mt-0">
                                <?php dynamic_sidebar('glowify-blog-single-sidebar'); ?>
                            </aside>
                        </div>
                    <?php endif; ?>
                <?php endif; ?>
            </div>
        </div>
    </div>
    
    <div class="cs_height_120 cs_height_lg_70"></div>
                        
</section>

	

<?php

get_footer();

