<?php
/**
 * Custom functions that act independently of the theme templates.
 *
 * Eventually, some of the functionality here could be replaced by core features.
 *
 * @package flossy
 */

/**
 * Adds custom classes to the array of body classes.
 *
 * @param array $classes Classes for the body element.
 * @return array
 */
function flossy_body_classes( $classes ) {
	// Adds a class of group-blog to blogs with more than 1 published author.
	if ( is_multi_author() ) {
		$classes[] = 'group-blog';
	}

	// Adds a class of hfeed to non-singular pages.
	if ( ! is_singular() ) {
		$classes[] = 'hfeed';
	}
	
	$classes[] = 'header1';
	
	if ( is_page_template( 'templates/template-homepage.php' ) ) {
		$classes[] = 'home1';
	}
	
	return $classes;
}
add_filter( 'body_class', 'flossy_body_classes' );

if ( ! function_exists( 'wp_body_open' ) ) {
	/**
	 * Backward compatibility for wp_body_open hook.
	 *
	 * @since 1.0.0
	 */
	function wp_body_open() {
		do_action( 'wp_body_open' );
	}
}

if (!function_exists('flossy_str_replace_assoc')) {

    /**
     * flossy_str_replace_assoc
     * @param  array $replace
     * @param  array $subject
     * @return array
     */
    function flossy_str_replace_assoc(array $replace, $subject) {
        return str_replace(array_keys($replace), array_values($replace), $subject);
    }
}


/**
 * Register widget area.
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 */

function flossy_widgets_init() {	
	register_sidebar( array(
		'name' => __( 'Header Widget Area 1', 'flossy' ),
		'id' => 'flossy-header-above-first',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget' => '</aside>',
		'before_title' => '<h5 class="widget-title">',
		'after_title' => '<span></span></h5>',
	) );
	
	register_sidebar( array(
		'name' => __( 'Header Widget Area 2', 'flossy' ),
		'id' => 'flossy-header-above-second',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget' => '</aside>',
		'before_title' => '<h5 class="widget-title">',
		'after_title' => '</h5>',
	) );
	
	register_sidebar( array(
		'name' => __( 'Sidebar Widget Area', 'flossy' ),
		'id' => 'flossy-sidebar-primary',
		'description' => __( 'The Primary Widget Area', 'flossy' ),
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget' => '</aside>',
		'before_title' => '<h4 class="widget-title"><span></span>',
		'after_title' => '</h4>',
	) );
	
	register_sidebar( array(
		'name' => __( 'Footer Widget', 'flossy' ),
		'id' => 'flossy-footer-widget',
		'description' => __( 'Footer Widget', 'flossy' ),
		'before_widget' => ' <div id="%1$s" class="%2$s widget col-sm-6 col-lg-3 middle-footer">',
		'after_widget' => '</aside></div>',
		'before_title' => '<h2 class="widget-title">',
		'after_title' => '</h2>',
	) );
	
	register_sidebar( array(
		'name' => __( 'WooCommerce Widget Area', 'flossy' ),
		'id' => 'flossy-woocommerce-sidebar',
		'description' => __( 'This Widget area for WooCommerce Widget', 'flossy' ),
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget' => '</aside>',
		'before_title' => '<h4 class="widget-title">',
		'after_title' => '</h4>',
	) );
}
add_action( 'widgets_init', 'flossy_widgets_init' );

/**
 * Flossy Logo
 */
if ( ! function_exists( 'flossy_logo' ) ) {
	function flossy_logo() {
		if(has_custom_logo())
			{	
				the_custom_logo();
			} 
			
			$flossy_site_title = get_bloginfo( 'name');
			if ($flossy_site_title) :
		?>
			<h4 class="site-title">
				<a href="<?php echo esc_url( home_url( '/' ) ); ?>">
					<?php echo esc_html($flossy_site_title);  ?>
				</a>
			</h4>	
		<?php endif; ?>
		<?php
			$flossy_site_desc = get_bloginfo( 'description');
			if ($flossy_site_desc) : ?>
				<p class="site-description"><?php echo esc_html($flossy_site_desc); ?></p>
		<?php endif;
	}
}
add_action( 'flossy_logo', 'flossy_logo' );


/**
 * Flossy Navigation
 */
if ( ! function_exists( 'flossy_main_nav' ) ) {
	function flossy_main_nav() {
		wp_nav_menu( 
			array(  
				'theme_location' => 'primary_menu',
				'container'  => '',
				'menu_class' => 'main-menu menu-wrap',
				'fallback_cb' => 'WP_Bootstrap_Navwalker::fallback',
				'walker' => new WP_Bootstrap_Navwalker()
				 ) 
			);
	}
}
add_action( 'flossy_main_nav', 'flossy_main_nav' );


/**
 * Flossy Normal Search
 */
if ( ! function_exists( 'flossy_hdr_normal_search' ) ) {
	function flossy_hdr_normal_search() {
		$hs_product_search	= get_theme_mod( 'hs_product_search','1'); 
		 if($hs_product_search=='1' ): ?>
			<div class="header-search-popup">
				<div class="search-overlay"></div>

				<div class="header-search-form product-search">
					<form name="product-search" method="POST"
						class="customize-unpreviewable">
						<div class="search-wrapper">
							<input type="search" name="s" class="search header-search-input" placeholder="<?php echo esc_attr__( 'Search for product...', 'flossy' ); ?>"
								value="">
							<svg xmlns="http://www.w3.org/2000/svg"
								xmlns:xlink="http://www.w3.org/1999/xlink"
								viewBox="0 0 471.701 471.701">
								<path
									d="M409.6,0c-9.426,0-17.067,7.641-17.067,17.067v62.344C304.667-5.656,164.478-3.386,79.411,84.479
											c-40.09,41.409-62.455,96.818-62.344,154.454c0,9.426,7.641,17.067,17.067,17.067S51.2,248.359,51.2,238.933
											c0.021-103.682,84.088-187.717,187.771-187.696c52.657,0.01,102.888,22.135,138.442,60.976l-75.605,25.207
											c-8.954,2.979-13.799,12.652-10.82,21.606s12.652,13.799,21.606,10.82l102.4-34.133c6.99-2.328,11.697-8.88,11.674-16.247v-102.4
											C426.667,7.641,419.026,0,409.6,0z">
								</path>
								<path
									d="M443.733,221.867c-9.426,0-17.067,7.641-17.067,17.067c-0.021,103.682-84.088,187.717-187.771,187.696
											c-52.657-0.01-102.888-22.135-138.442-60.976l75.605-25.207c8.954-2.979,13.799-12.652,10.82-21.606
											c-2.979-8.954-12.652-13.799-21.606-10.82l-102.4,34.133c-6.99,2.328-11.697,8.88-11.674,16.247v102.4
											c0,9.426,7.641,17.067,17.067,17.067s17.067-7.641,17.067-17.067v-62.345c87.866,85.067,228.056,82.798,313.122-5.068
											c40.09-41.409,62.455-96.818,62.344-154.454C460.8,229.508,453.159,221.867,443.733,221.867z">
								</path>
							</svg>

						</div>
						<?php if(class_exists( 'woocommerce' ) && function_exists( 'flossy_get_product_categories_hierarchy' )){
							$categories = flossy_get_product_categories_hierarchy(); ?>
						<?php if ($categories): ?>
							<select name="category" class="category header-search-select">
								<option class="default" value=""><?php echo esc_html__( 'Category', 'flossy' ); ?></option>
								<?php flossy_list_product_taxonomy_hierarchy_no_instance( $categories); ?>
							</select>
						<?php endif; } ?>
						
						<input type="hidden" name="post_type"
							value="product">
						<button class="header-search-button"
							type="submit"><i
								class="fa fa-search"></i></button>
					</form>
					<div class="search-results woocommerce"></div>
				</div>
				<button type="button" class="close-style header-search-close"></button>
			</div>
		<?php endif;
	}
}
add_action( 'flossy_hdr_normal_search', 'flossy_hdr_normal_search' );


/**
 * Flossy Header My Account
 */
if ( ! function_exists( 'flossy_hdr_account' ) ) {
	function flossy_hdr_account() {
		$hide_show_account 		= get_theme_mod( 'hide_show_account','1');
		if($hide_show_account=='1'  && class_exists( 'woocommerce' )): ?>
			<li class="user">
				<?php if(is_user_logged_in()): ?>
					<a href="<?php echo esc_url(wp_logout_url( home_url())); ?>" class="user-btn"><i class="fa fa-sign-out"></i></a>
				<?php else: ?>
					<a href="<?php echo esc_url(get_permalink( get_option('woocommerce_myaccount_page_id')) ); ?>" class="user-btn"><i class="fa fa-sign-in"></i></a>
				<?php endif; ?>	
		<?php endif;
	}
}
add_action( 'flossy_hdr_account', 'flossy_hdr_account' );


/**
 * Flossy Header Cart
 */
if ( ! function_exists( 'flossy_hdr_cart' ) ) {
	function flossy_hdr_cart() {	
		$hide_show_cart = get_theme_mod( 'hide_show_cart','1');
		$hdr_cart_close= get_theme_mod( 'hdr_cart_close','CLOSE');
		if($hide_show_cart=='1' && class_exists( 'woocommerce' )): ?>
			<li class="cart-wrapper">
				<div class="cart-main">
					<button type="button" class="cart-icon-wrap header-cart cart-trigger cart">
						<i class="jcs ja-cart"></i>
						<?php 
							if ( class_exists( 'woocommerce' ) ) {
								$count = WC()->cart->cart_contents_count;
								$cart_url = wc_get_cart_url();
								
								if ( $count > 0 ) {
								?>
									 <span class="cart-count count"><?php echo esc_html( $count ); ?></span>
								<?php 
								}
								else {
									?>
									<span class="cart-count count"><?php echo esc_html('0','flossy')?></span>
									<?php 
								}
							}
							?>
					</button>	
				</div>
				<div class="cart-modal cart-modal-1">
					<div class="cart-container">
						<div class="cart-header">
							<div class="cart-top">
								<span class="cart-text"><?php echo esc_html__('Cart','flossy') ?></span>
								<a href="javascript:void(0);" class="cart-close"><?php echo wp_kses_post($hdr_cart_close); ?></a>
							</div>
						</div>
						<div class="cart-data">
							<?php get_template_part('woocommerce/cart/mini','cart'); ?>
						</div>	
					</div>
					<div class="cart-overlay"></div>
				</div>
			</li>
			<?php endif;
	}
}
add_action( 'flossy_hdr_cart', 'flossy_hdr_cart' );



/**
 * Flossy Browse Category
 */
if ( ! function_exists( 'flossy_hdr_browse_cat' ) ) {
	function flossy_hdr_browse_cat() {
		$browse_cat_ttl		= get_theme_mod( 'browse_cat_ttl','<i class="fa fa-list-ul"></i> Browse Categories');
		$browse_product_cat			= get_theme_mod('browse_product_cat');
		
		if(class_exists( 'woocommerce' )): 
		?>
		<button type="button" class="product-category-btn">
			<span class="cat-left">
				<?php echo wp_kses_post($browse_cat_ttl); ?>
			</span>
			<i class="fa fa-spinner"></i>
		</button>
		<div class="product-category-menus">
			<div class="product-category-menus-list">
				<ul class="main-menu">
						<?php
						$taxonomy     = 'product_cat';
						$orderby      = 'name';
						$show_count   = 0;
						$pad_counts   = 0;
						$hierarchical = 1;
						$title        = '';
						$empty        = 0;
						$args = array(
							'taxonomy'     => $taxonomy,
							'orderby'      => $orderby,
							'show_count'   => $show_count,
							'pad_counts'   => $pad_counts,
							'hierarchical' => $hierarchical,
							'title_li'     => $title,
							'hide_empty'   => $empty
						);
						
						$all_categories = get_categories( $args );
						foreach ($all_categories as $cat) {
							$flossy_product_cat_icon = get_term_meta($cat->term_id, 'flossy_product_cat_icon', true);
							if($cat->category_parent == 0) {
								$category_id = $cat->term_id;
								$child_class = (flossy_has_Children($category_id))?'menu-item-has-children':'';
								
								echo '<li class="menu-item main-top-menu '.$child_class.'"><a href="'.get_term_link($cat->slug, 'product_cat').'">'.(!empty($flossy_product_cat_icon) ? "<i class='fa {$flossy_product_cat_icon}'></i>":''); echo $cat->name.'</a>';
								$args2 = array(
									'taxonomy'     => $taxonomy,
									'parent'       => $category_id,
									'hierarchical' => $hierarchical,
									'hide_empty'   => $empty
								);
								$sub_cats = get_categories( $args2 );
								if($sub_cats) {
									echo '<ul class="dropdown-menu 2-main-top-menu">';
									foreach($sub_cats as $sub_category) {
										$child_class = (flossy_has_Children($sub_category->term_id))?'menu-item-has-children':'';
										
								
										$flossy_product_cat_icon = get_term_meta($sub_category->term_id, 'flossy_product_cat_icon', true);
										echo  '<li class="menu-item '.$child_class.'"><a class="nav-link" href="'. get_term_link($sub_category->slug, 'product_cat') .'">'.(!empty($flossy_product_cat_icon) ? "<i class='fa {$flossy_product_cat_icon}'></i>":''); echo $sub_category->name .'</a>';
										
										$args3 = array(
											'taxonomy'     => $taxonomy,
											'parent'       => $sub_category->term_id,
											'hierarchical' => $hierarchical,
											'hide_empty'   => $empty
										);
										$sub_cats3 = get_categories( $args3 );
									
										if($sub_cats3) {
											echo '<ul class="dropdown-menu 3-main-top-menu">';
											foreach($sub_cats3 as $sub_category3) {
												$child_class = (flossy_has_Children($sub_category3->term_id))?'menu-item-has-children':'';
												
												$flossy_product_cat_icon = get_term_meta($sub_category3->term_id, 'flossy_product_cat_icon', true);
												echo  '<li class="menu-item '.$child_class.'"><a class="nav-link" href="'. get_term_link($sub_category3->slug, 'product_cat') .'">'.(!empty($flossy_product_cat_icon) ? "<i class='fa {$flossy_product_cat_icon}'></i>":''); echo $sub_category3->name .'</a>';
												
												$args4 = array(
													'taxonomy'     => $taxonomy,
													'parent'       => $sub_category3->term_id,
													'hierarchical' => $hierarchical,
													'hide_empty'   => $empty
												);
												$sub_cats4 = get_categories( $args4 );
												if($sub_cats4) {
													echo '<ul class="dropdown-menu 4-main-top-menu">';
													foreach($sub_cats4 as $sub_category4) {
														$child_class = (flossy_has_Children($sub_category4->term_id))?'menu-item-has-children':'';
														
														$flossy_product_cat_icon = get_term_meta($sub_category4->term_id, 'flossy_product_cat_icon', true);
														echo  '<li class="menu-item '.$child_class.'"><a class="nav-link" href="'. get_term_link($sub_category4->slug, 'product_cat') .'">'.(!empty($flossy_product_cat_icon) ? "<i class='fa {$flossy_product_cat_icon}'></i>":''); echo $sub_category4->name .'</a>';
														
														$args5 = array(
															'taxonomy'     => $taxonomy,
															'parent'       => $sub_category4->term_id,
															'hierarchical' => $hierarchical,
															'hide_empty'   => $empty
														);
														
														$sub_cats5 = get_categories( $args5 );
														if($sub_cats5) {
															echo '<ul class="dropdown-menu 5-main-top-menu">';
															foreach($sub_cats5 as $sub_category5) {
																$child_class = (flossy_has_Children($sub_category5->term_id))?'menu-item-has-children':'';
																
																$flossy_product_cat_icon = get_term_meta($sub_category5->term_id, 'flossy_product_cat_icon', true);
																echo  '<li class="menu-item '.$child_class.'"><a class="nav-link" href="'. get_term_link($sub_category5->slug, 'product_cat') .'">'.(!empty($flossy_product_cat_icon) ? "<i class='fa {$flossy_product_cat_icon}'></i>":''); echo $sub_category5->name .'</a>';
																
																$args6 = array(
																	'taxonomy'     => $taxonomy,
																	'parent'       => $sub_category5->term_id,
																	'hierarchical' => $hierarchical,
																	'hide_empty'   => $empty
																);
																
																$sub_cats6 = get_categories( $args6 );
																
																if($sub_cats6) {
																	echo '<ul class="dropdown-menu 6-main-top-menu">';
																	foreach($sub_cats6 as $sub_category6) {
																		$child_class = (flossy_has_Children($sub_category6->term_id))?'menu-item-has-children':'';
																		
																		$flossy_product_cat_icon = get_term_meta($sub_category6->term_id, 'flossy_product_cat_icon', true);
																		echo  '<li class="menu-item '.$child_class.'"><a class="nav-link" href="'. get_term_link($sub_category6->slug, 'product_cat') .'">'.(!empty($flossy_product_cat_icon) ? "<i class='fa {$flossy_product_cat_icon}'></i>":''); echo $sub_category6->name .'</a></li>';
																	}
																	echo '</ul>';
																}
																echo '</li>';
															}
															echo '</ul>';
														}
														echo '</li>';
													}
													echo '</ul>';
												}
												echo '</li>';
											}
											echo '</ul>';
										}	
										echo '</li>';
										}
										echo '</ul>';
									}
									echo '</li>';
								}
							}
						?>
					</ul>
			</div>
		</div>
		<?php
		endif;
	}
}
add_action( 'flossy_hdr_browse_cat', 'flossy_hdr_browse_cat' );

/**
 * Flossy Mobile Browse Category
 */
if ( ! function_exists( 'flossy_hdr_mobile_browse_cat' ) ) {
	function flossy_hdr_mobile_browse_cat() {
		$hs_browse_cat		= get_theme_mod( 'hs_browse_cat','1');
		$browse_cat_ttl		= get_theme_mod( 'browse_cat_ttl','<i class="fa fa-list-ul"></i> Browse Categories');
		$menu_ttl		= get_theme_mod( 'menu_ttl','Menu');
		?>
		<div class="switcher-tab">
			<button class="active-bg"><?php echo esc_html($menu_ttl);?></button>
			<button class="cat-menu-bt"><?php echo wp_kses_post($browse_cat_ttl); ?></button>
		</div>
		<?php if($hs_browse_cat=='1' && class_exists( 'woocommerce' )): ?>
			<div class="product-categories d-none">
				<div class="product-categories-list">
					<ul class="main-menu">
						<?php
							$categories = array(
								  'taxonomy' => 'product_cat',
								  'hide_empty' => false,
								  'parent'   => 0
							  );
							$product_cat = get_terms( $categories );
							foreach ($product_cat as $parent_product_cat) {
								$child_args = array(
									'taxonomy' => 'product_cat',
									'hide_empty' => false,
									'parent'   => $parent_product_cat->term_id
								);
								$thumbnail_id = get_term_meta( $parent_product_cat->term_id, 'thumbnail_id', true );
								$image = wp_get_attachment_url( $thumbnail_id );
								$child_product_cats = get_terms( $child_args );
								$flossy_product_cat_icon = get_term_meta($parent_product_cat->term_id, 'flossy_product_cat_icon', true);
								if ( ! empty($child_product_cats) ) {
									echo '<li class="menu-item menu-item-has-children"><a href="'.get_term_link($parent_product_cat->term_id).'" class="nav-link">'.(!empty($flossy_product_cat_icon) ? "<i class='fa {$flossy_product_cat_icon}'></i>":''); echo $parent_product_cat->name.'</a><span class="mobile-collapsed d-lg-none"><button type="button" class="fa fa-chevron-right" aria-label="Mobile Collapsed"></button></span>';
								} else {
									echo '<li class="menu-item"><a href="'.get_term_link($parent_product_cat->term_id).'" class="nav-link">'.(!empty($flossy_product_cat_icon) ? "<i class='fa {$flossy_product_cat_icon}'></i>":''); echo $parent_product_cat->name.'</a>';
								}
								if ( ! empty($child_product_cats) ) {
									echo '<ul class="dropdown-menu">';
									foreach ($child_product_cats as $child_product_cat) {
									echo '<li class="menu-item"><a href="'.get_term_link($child_product_cat->term_id).'" class="dropdown-item">'.$child_product_cat->name.'</a></li>';
									} echo '</ul>';
								} echo '</li>';
							} ?>
					</ul>
				</div>
			</div>
		<?php endif;
	}
}
add_action( 'flossy_hdr_mobile_browse_cat', 'flossy_hdr_mobile_browse_cat' );


/**
 * Flossy Product Search
 */
if ( ! function_exists( 'flossy_hdr_product_search' ) ) {
	function flossy_hdr_product_search() {
		$flossy_hs_product_search	= get_theme_mod( 'hs_product_search','1');
		 if($flossy_hs_product_search=='1' && class_exists( 'woocommerce' )): ?>
			<div class="header-search-form">
				<form method="get" action="<?php echo esc_url(home_url('/')); ?>">
					<select class="header-search-select" name="product_cat">
					   <option value=""><?php esc_html_e('Select Category', 'flossy'); ?></option> 
						<?php
							$storely_product_categories = get_categories('taxonomy=product_cat');
							foreach ($storely_product_categories as $category) {
								$option = '<option value="' . esc_attr($category->category_nicename) . '">';
								$option .= esc_html($category->cat_name);
								$option .= ' (' . absint($category->category_count) . ')';
								$option .= '</option>';
								echo $option; // WPCS: XSS OK.
							}
						?>
					</select>
					<input type="hidden" name="post_type" value="product" />
					<input class="header-search-input" name="s" type="text"
						placeholder="<?php esc_attr_e('Search Products Here', 'flossy'); ?>" />
					<input type="hidden" name="post_type" value="product" />
					<button class="header-search-button" type="submit"><i class="fa fa-search"></i></button>
				</form>
			</div>
		<?php endif;
	}
}
add_action( 'flossy_hdr_product_search', 'flossy_hdr_product_search' );

 /**
 * Add WooCommerce Cart Icon With Cart Count (https://isabelcastillo.com/woocommerce-cart-icon-count-theme-header)
 */
function flossy_add_to_cart_count_fragment( $fragments ) {
	
    ob_start();
    $count = WC()->cart->cart_contents_count; 
    ?> 	
	<?php
    if ( $count > 0 ) {
	?>
		 <span class="cart-counts"><?php echo esc_html( $count ); ?></span>
	<?php 
	}
	else {
		?>
		<span class="cart-counts"><?php esc_html_e('0','flossy')?></span>
		<?php 
	}
    ?><?php
 
    $fragments['span.cart-counts'] = ob_get_clean();
     
    return $fragments;
}
add_filter( 'woocommerce_add_to_cart_fragments', 'flossy_add_to_cart_count_fragment' );


function flossy_add_to_cart_total_fragment( $fragments ) {
	
    ob_start(); 
    ?> 	
	<span class="cart-label">
		<span><?php echo WC()->cart->get_cart_subtotal(); ?></span>
	</span>
   <?php
    $fragments['span.cart-label'] = ob_get_clean();
     
    return $fragments;
}
add_filter( 'woocommerce_add_to_cart_fragments', 'flossy_add_to_cart_total_fragment' );


/**
 * This Function Check whether Sidebar active or Not
 */
if(!function_exists( 'flossy_blog_column_layout' )) :
function flossy_blog_column_layout(){
	if(is_active_sidebar('flossy-sidebar-primary'))
		{ echo 'col-lg-8'; } 
	else 
		{ echo 'col-lg-12'; }  
} endif;
 
 
 
/**
 * Flossy Breadcrumb
 */ 
function flossy_breadcrumbs() {
	
	$showOnHome	= esc_html__('1','flossy'); 	// 1 - Show breadcrumbs on the homepage, 0 - don't show
	$delimiter 	= '';   // Delimiter between breadcrumb
	$home 		= esc_html__('Home','flossy'); 	// Text for the 'Home' link
	$showCurrent= esc_html__('1','flossy'); // Current post/page title in breadcrumb in use 1, Use 0 for don't show
	$breadcrumb_seprator	= get_theme_mod('breadcrumb_seprator','-');
	global $post;
	$homeLink = home_url();

	if (is_home() || is_front_page()) {
 
	if ($showOnHome == 1) echo '<a href="' . esc_url($homeLink) . '" class="focus">  ' . esc_html($home) . '</a>';
 
	} else {
 
    echo '<a href="' . esc_url($homeLink) . '" class="focus">  ' . esc_html($home) . '</a> ' . '&nbsp' . wp_kses_post($breadcrumb_seprator) . '&nbsp';
 
    if ( is_category() ) 
	{
		$thisCat = get_category(get_query_var('cat'), false);
		if ($thisCat->parent != 0) echo get_category_parents($thisCat->parent, TRUE, ' ' . ' ');
		echo esc_html__('Archive by category','flossy').' "' . esc_html(single_cat_title('', false)) . '"' ;
		
	} 
	
	elseif ( is_search() ) 
	{
		echo esc_html__('Search results for ','flossy').' "' . esc_html(get_search_query()) . '"' ;
	} 
	
	elseif ( is_day() )
	{
		echo '<a href="' . esc_url(get_year_link(get_the_time('Y'))) . '"  class="focus">' . esc_html(get_the_time('Y')) . '</a> ' . '&nbsp' . wp_kses_post($breadcrumb_seprator) . '&nbsp';
		echo '<a href="' . esc_url(get_month_link(get_the_time('Y'),get_the_time('m'))) . '" class="dfdsfdsf">' . esc_html(get_the_time('F')) . '</a> '. '&nbsp' . wp_kses_post($breadcrumb_seprator) . '&nbsp';
		echo esc_html(get_the_time('d')) ;
	} 
	
	elseif ( is_month() )
	{
		echo '<a href="' . esc_url(get_year_link(get_the_time('Y'))) . '"  class="focus">' . esc_html(get_the_time('Y')) . '</a> ' . esc_attr($delimiter) . '&nbsp' . wp_kses_post($breadcrumb_seprator) . '&nbsp';
		echo esc_html(get_the_time('F')) ;
	} 
	
	elseif ( is_year() )
	{
		echo esc_html(get_the_time('Y')) ;
	} 
	
	elseif ( is_single() && !is_attachment() )
	{
		if ( get_post_type() != 'post' )
		{
			$post_type = get_post_type_object(get_post_type());
			$slug = $post_type->rewrite;
			echo '<a href="' . esc_url($homeLink) . '/' . $slug['slug'] . '/" class="focus">  ' . $post_type->labels->singular_name . '</a>';
			if ($showCurrent == 1) echo ' ' . esc_attr($delimiter) . '&nbsp' . wp_kses_post($breadcrumb_seprator) . '&nbsp' . wp_kses_post(get_the_title()) ;
		}
		else
		{
			$cat = get_the_category(); $cat = $cat[0];
			$cats = get_category_parents($cat, TRUE, ' ' . esc_attr($delimiter) . '&nbsp' . wp_kses_post($breadcrumb_seprator) . '&nbsp');
			if ($showCurrent == 0) $cats = preg_replace("#^(.+)\s$delimiter\s$#", "$1", $cats);
			echo $cats;
			if ($showCurrent == 1) echo esc_html(get_the_title()) ;
		}
 
    }
		
	elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) {
		if ( class_exists( 'WooCommerce' ) ) {
			if ( is_shop() ) {
				$thisshop = woocommerce_page_title();
			}
		}	
		else  {
			$post_type = get_post_type_object(get_post_type());
			echo $post_type->labels->singular_name ;
		}	
	} 
	
	elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) 
	{
		$post_type = get_post_type_object(get_post_type());
		echo $post_type->labels->singular_name ;
	} 
	
	elseif ( is_attachment() ) 
	{
		$parent = get_post($post->post_parent);
		$cat = get_the_category($parent->ID); 
		if(!empty($cat)){
		$cat = $cat[0];
		echo get_category_parents($cat, TRUE, ' ' . esc_attr($delimiter) . '&nbsp' . wp_kses_post($breadcrumb_seprator) . '&nbsp');
		}
		echo '<a href="' . esc_url(get_permalink($parent)) . '">' . $parent->post_title . '</a>';
		if ($showCurrent == 1) echo ' ' . esc_attr($delimiter) . ' ' . esc_html(get_the_title()) ;
 
    } 
	
	elseif ( is_page() && !$post->post_parent ) 
	{
		if ($showCurrent == 1) echo esc_html(get_the_title()) ;
	} 
	
	elseif ( is_page() && $post->post_parent ) 
	{
		$parent_id  = $post->post_parent;
		$breadcrumbs = array();
		while ($parent_id) 
		{
			$page = get_page($parent_id);
			$breadcrumbs[] = '<a href="' . esc_url(get_permalink($page->ID)) . '" class="focus">' . esc_html(get_the_title($page->ID)) . '</a>' . '&nbsp' . wp_kses_post($breadcrumb_seprator) . '&nbsp';
			$parent_id  = $page->post_parent;
		}
		
		$breadcrumbs = array_reverse($breadcrumbs);
		for ($i = 0; $i < count($breadcrumbs); $i++) 
		{
			echo $breadcrumbs[$i];
			// if ($i != count($breadcrumbs)-1) echo ' ' . esc_attr($delimiter) . '&nbsp' . wp_kses_post($breadcrumb_seprator) . '&nbsp';
		}
		if ($showCurrent == 1) echo ' ' . esc_attr($delimiter) . ' ' . esc_html(get_the_title()) ;
 
    } 
	elseif ( is_tag() ) 
	{
		echo esc_html__('Posts tagged ','flossy').' "' . esc_html(single_tag_title('', false)) . '"' ;
	} 
	
	elseif ( is_author() ) {
		global $author;
		$userdata = get_userdata($author);
		echo esc_html__('Articles posted by ','flossy').'' . $userdata->display_name ;
	} 
	
	elseif ( is_404() ) {
		echo esc_html__('Error 404 ','flossy');
    }
	
    if ( get_query_var('paged') ) {
		if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo '';
		echo ' ( ' . esc_html__('Page','flossy') . '' . esc_html(get_query_var('paged')). ' )';
		if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo '';
    }
 
  }
}
?>