<?php
/*
Template Name: Blog Template
*/
get_header(); deep_print_menu();

	$deep_thisPostID = get_the_ID(); $deep_color_code = get_option("deep_style_color");

	if ((get_post_meta($deep_thisPostID, "deep_enable_custom_pagetitle_options_value", true) == "no" || !get_post_meta($deep_thisPostID, "deep_enable_custom_pagetitle_options_value", true)) || (defined('DEEP_IS_FIRST_PAGE') && DEEP_IS_FIRST_PAGE)){
		$type = get_option("deep_header_type");
		$thecolor = deep_hex2rgb(str_replace("__USE_THEME_MAIN_COLOR__", $deep_color_code, get_option("deep_header_color"))); 
		$opacity = intval(str_replace("%","",get_option("deep_header_opacity")))/100;
		$color = "rgba(".$thecolor[0].",".$thecolor[1].",".$thecolor[2].",".$opacity.")";
		$image = get_option("deep_header_image"); 
		$background_position = get_option("deep_pagetitle_background_position");
		$pattern = is_string(get_option("deep_header_pattern")) ? DEEP_PATTERNS_URL.get_option("deep_header_pattern") : ""; 
		$custompattern = get_option("deep_header_custom_pattern"); 
		$margintop = get_option("deep_header_text_margin_top");	
		$banner = get_option("deep_banner_slider");
		$showtitle = get_option("deep_hide_pagetitle") == "on" ? true : false;
		$showsectitle = get_option("deep_hide_sec_pagetitle") == "on" ? true : false;
		$tcolor = get_option("deep".'_header_text_color');
		$tsize = intval(str_replace(" ", "", get_option("deep".'_header_text_size')),10)."px";
		
		/* New 4.0 */
		$letterspacing = intval(str_replace(" ", "", get_option("deep".'_header_text_letterspacing')),10)."px";
		$titlelineheight = get_option("deep".'_header_text_lineheight');
		$titletransform = get_option("deep_header_text_transform");
		
		$titlesecletterspacing = intval(str_replace(" ", "", get_option("deep".'_secondary_title_text_letterspacing')),10)."px";
		$titleseclineheight = get_option("deep".'_secondary_title_text_lineheight');
		$titlesectransform = get_option("deep_secondary_title_text_transform");
		
		$tfont = get_option("deep".'_header_text_font');
		$stcolor = get_option("deep".'_secondary_title_text_color');
		$stsize = intval(str_replace(" ", "", get_option("deep".'_secondary_title_text_size')),10)."px";
		$stfont = get_option("deep".'_secondary_title_font');
		$stmargin = intval(str_replace(" ", "", get_option("deep".'_header_sec_text_margin_top')),10)."px";
		$originalalign = get_option("deep_header_text_alignment");
		$pt_parallax = get_option("deep_pagetitle_image_parallax") == "on" ? true : false;
		$pt_overlay = get_option("deep_pagetitle_image_overlay") == "on" ? true : false;
		$pt_overlay_type = get_option("deep_pagetitle_overlay_type");
		$pt_overlay_the_color = deep_hex2rgb(str_replace("__USE_THEME_MAIN_COLOR__", $deep_color_code, get_option("deep_pagetitle_overlay_color")));
		$pt_overlay_pattern = (is_string(get_option("deep_pagetitle_overlay_pattern"))) ? DEEP_PATTERNS_URL.get_option("deep_pagetitle_overlay_pattern") : "";
		$pt_overlay_opacity = intval(str_replace("%","",get_option("deep_pagetitle_overlay_opacity")))/100;
		$pt_overlay_color = "rgba(".$pt_overlay_the_color[0].",".$pt_overlay_the_color[1].",".$pt_overlay_the_color[2].",".$pt_overlay_opacity.")";
		$breadcrumbs = get_option("deep_breadcrumbs");
		$breadcrumbs_margintop = get_option('deep_breadcrumbs_text_margin_top');
		$pagetitlepadding = get_option('deep_page_title_padding');
	} else {
		$type = get_post_meta($deep_thisPostID, "deep_header_type_value", true);
		$thecolor = deep_hex2rgb(get_post_meta($deep_thisPostID, "deep_header_color_value", true)); 
		$opacity = intval(str_replace("%","",get_post_meta($deep_thisPostID, "deep_header_color_opacity_value", true)))/100;
		$color = "rgba(".$thecolor[0].",".$thecolor[1].",".$thecolor[2].",".$opacity.")";
		$image = get_post_meta($deep_thisPostID, "deep_header_image_value", true);
		$image = explode('|!|',$image);
		if (isset($image[1])) $image = explode('|*|',$image[1]);
		$image = $image[0];
		$background_position = get_post_meta($deep_thisPostID, "deep_header_background_position_value", true);
		$pattern = DEEP_PATTERNS_URL.get_post_meta($deep_thisPostID, "deep_header_pattern_value", true).".jpg";
		$custompattern = get_option("deep_header_custom_pattern_value"); 
		$margintop = get_post_meta($deep_thisPostID, "deep_header_text_margin_top_value", true);
		$banner = get_post_meta($deep_thisPostID, "deep_banner_slider_value", true);
		$showtitle = get_post_meta($deep_thisPostID, "deep_hide_pagetitle_value", true) == "yes" ? true : false;
		$showsectitle = get_post_meta($deep_thisPostID, "deep_hide_sec_pagetitle_value", true) == "yes" ? true : false;
		$tcolor = get_post_meta($deep_thisPostID, "deep_header_text_color_value", true);
		$tsize = intval(str_replace(" ", "", get_post_meta($deep_thisPostID, "deep_header_text_size_value", true)),10)."px";
		
		/* New 4.0 */
		$letterspacing = intval(str_replace(" ", "", get_post_meta($deep_thisPostID, "deep_header_text_letterspacing_value", true)),10)."px";
		$titlelineheight = get_post_meta($deep_thisPostID, "deep_header_text_lineheight_value", true);
		$titletransform = get_post_meta($deep_thisPostID, "deep_header_text_transform_value", true);

		$titlesecletterspacing = intval(str_replace(" ", "", get_post_meta($deep_thisPostID, "deep_secondary_title_text_letterspacing_value", true)),10)."px";
		$titleseclineheight = get_post_meta($deep_thisPostID, "deep_secondary_title_text_lineheight_value", true);
		$titlesectransform = get_post_meta($deep_thisPostID, "deep_secondary_title_text_transform_value", true);
		
		$tfont = get_post_meta($deep_thisPostID, "deep_header_text_font_value", true);
		$stcolor = get_post_meta($deep_thisPostID, "deep_secondary_title_text_color_value", true);
		$stsize = intval(str_replace(" ", "", get_post_meta($deep_thisPostID, "deep_secondary_title_text_size_value", true)),10)."px";
		$stfont = get_post_meta($deep_thisPostID, "deep_secondary_title_font_value", true);
		$stmargin = intval(str_replace(" ", "", get_post_meta($deep_thisPostID, "deep_header_secondary_text_margin_top_value", true)),10)."px";
		$originalalign = get_post_meta($deep_thisPostID, "deep_header_text_alignment_value", true);
		$pt_parallax = get_post_meta($deep_thisPostID, "deep_pagetitle_image_parallax_value", true) == "on" ? true : false;
		$pt_overlay = get_post_meta($deep_thisPostID, "deep_pagetitle_image_overlay_value", true) == "on" ? true : false;
		$pt_overlay_type = get_post_meta($deep_thisPostID, "deep_pagetitle_overlay_type_value", true);
		$pt_overlay_the_color = deep_hex2rgb(get_post_meta($deep_thisPostID, "deep_pagetitle_overlay_color_value", true));
		$pt_overlay_pattern = DEEP_PATTERNS_URL.get_post_meta($deep_thisPostID, "deep_pagetitle_overlay_pattern_value", true).".jpg";
		$pt_overlay_opacity = intval(str_replace("%","",get_post_meta($deep_thisPostID, "deep_pagetitle_overlay_opacity_value", true)))/100;
		$pt_overlay_color = "rgba(".$pt_overlay_the_color[0].",".$pt_overlay_the_color[1].",".$pt_overlay_the_color[2].",".$pt_overlay_opacity.")";
		$breadcrumbs = get_post_meta($deep_thisPostID, "deep_enable_breadcrumbs_value", true) == "yes" ? "on" : "off";
		$breadcrumbs_margintop = intval(str_replace(" ", "", get_post_meta($deep_thisPostID, "deep_breadcrumbs_margin_top_value", true)),10)."px";
		$pagetitlepadding = intval(str_replace(" ", "", get_post_meta($deep_thisPostID, "deep_page_title_padding_value", true)),10)."px";
	}
	$height = "auto";
	
	$textalign = $originalalign;
	if ($originalalign == "titlesleftcrumbsright") $textalign = "left";
	if ($originalalign == "titlesrightcrumbsleft") $textalign = "right";
	
	if (is_array($tfont)) $tfont = ""; $deep_import_fonts[] = $tfont;
	$principalfont = explode("|",$tfont);
	$principalfont[0] = $principalfont[0]."', 'Arial', 'sans-serif";
	if (!isset($principalfont[1])) $principalfont[1] = "";
		
	if (is_array($stfont)) $stfont = ""; $deep_import_fonts[] = $stfont;
	$secondaryfont = explode("|",$stfont);
	$secondaryfont[0] = $secondaryfont[0]."', 'Arial', 'sans-serif";
	if (!isset($secondaryfont[1])) $secondaryfont[1] = "";
	
	if ($type != "without"){
		
		$ptitleaux = $bcaux = "";
		if ($originalalign == "titlesleftcrumbsright" || $originalalign == "titlesrightcrumbsleft"){
    		$ptitleaux .= "max-width: 50%;";
    		$bcaux .= "max-width: 50%;";
    		if ($originalalign == "titlesleftcrumbsright"){
				$ptitleaux .= "float:left;";
				$bcaux .= "float:right;";
			} else {
				$ptitleaux .= "float:right;";
				$bcaux .= "float:left;";
			}
		}
		$bcaux .= "margin-top:".intval($breadcrumbs_margintop,10)."px;";
		switch($originalalign){
			case "left": case "titlesrightcrumbsleft":
				$bcaux .= "text-align: left;";
			break;
			case "right": case "titlesleftcrumbsright":
				$bcaux .= "text-align:right;";
			break;
			case "center": 
				$bcaux .= "text-align:center;";
			break;
		}
		?>
		<div class="fullwidth-container <?php if ($type == "pattern") echo "bg-pattern"; ?> <?php if ($pt_parallax) echo "parallax"; ?><?php if (($type == "image" || $type == "pattern") && get_option('deep_enable_grayscale') == 'on') echo " deep_grayscale "; ?>" <?php if ($pt_parallax) echo 'data-stellar-ratio="0.5"'; ?> 
	    	<?php
		    	$deep_output = ".fullwidth-container{";
		 		if ($height != "") $deep_output.= "height: ". $height . ";";
				if ($type == "none") $deep_output.= "background: none !important;"; 
				if ($type == "color") $deep_output.= "background: " . $color . " !important;";
				if ($type == "image") $deep_output.= "background: url(" . $image . ") no-repeat !important; background-size: 100% auto;";  
	 			if ($type == "pattern") $deep_output.= "background: url('" . $pattern . "') 0 0 repeat !important;";
				$deep_output .= "}";
				deep_set_custom_inline_css($deep_output);
				
				
	    	?> <?php if ($type == "image" && !$pt_parallax) echo ' data-background-alignment="'. esc_attr( $background_position ) .'" '; ?>>
	    	<?php
		    	if ($type == "image" && $pt_overlay){
			    	$deep_output = ".pagetitle_overlay{";
			    	echo '<div class="pagetitle_overlay"></div> '; 
			    	if ($pt_overlay_type == "color") $deep_output.= 'background-color:'.$pt_overlay_color.' !important';
			    	else $deep_output.= 'background:url('.$pt_overlay_pattern.') repeat;opacity:'.$pt_overlay_opacity.' !important;';
			    	$deep_output .= "}";
					deep_set_custom_inline_css($deep_output);
		    	}
		    	if ($type === "banner"){
			    	?> 
			    	<div class="revBanner">
				    	<?php
					    	if (substr($banner, 0, 10) === "revSlider_"){
								if (!function_exists('putRevSlider')){
									echo esc_html__('Please install the missing plugin - Revolution Slider.', 'deep');
								} else {
									putRevSlider(substr($banner, 10));
								}
							} 
							if (substr($banner, 0, 13) === "masterSlider_"){
								if (!function_exists('masterslider')){
									echo esc_html__('Please install the missing plugin - MasterSlider.', 'deep');
								} else {
									echo do_shortcode( '[masterslider alias="'.substr($banner, 13).'"]' );
								}
							}
							if (substr($banner, 0, 12) === "layerSlider_"){
								if (!function_exists('layerslider')){
									echo esc_html__('Please install the missing plugin - LayerSlider.', 'deep');
								} else {
									echo do_shortcode( '[layerslider id="'.substr($banner, 12).'"]' );
								}
							}
				    	?>
				    </div> 
				    <?php
		    	} else {
		    	?>
				<div class="container present-container <?php echo esc_attr($originalalign); ?>">
					<?php
						$deep_output = ".present-container{padding: ".esc_attr($pagetitlepadding)." 15px;}";
						deep_set_custom_inline_css($deep_output);
					?>
					<div class="pageTitle">
					<?php
						$deep_output = ".present-container .pageTitle{text-align: ".esc_attr($textalign).";".esc_attr($ptitleaux)."}";
						deep_set_custom_inline_css($deep_output);
						if ($showtitle){
							?>
							<h1 class="page_title">
								<?php if (is_front_page() && is_home()) echo wp_kses(get_option('deep_blog_single_primary_title'), 'post'); else echo wp_kses(get_the_title($deep_thisPostID), 'post'); ?>
							</h1>
							<?php
							
							/* New 4.0 */	
							$deep_output = ".present-container h1.page_title{color: #$tcolor; font-size: $tsize; 
							
							letter-spacing: $letterspacing; line-height: $titlelineheight; text-transform: $titletransform;";
							
							if ($margintop != "") $deep_output .= esc_attr("margin-top: ".intval($margintop,10)."px;");
							if ($originalalign === "center") $deep_output .= esc_attr("text-indent: ".($letterspacing).";");
							
							$deep_output .= "}";
							deep_set_custom_inline_css($deep_output);
						}
		    			if ($showsectitle){
			    			if (get_post_meta($post->ID, 'secondaryTitle_value', true) != "" || get_option('deep_blog_secondary_title') != ""){
						    	?>
							    <h2 class="secondaryTitle">
							    	<?php echo wp_kses(get_post_meta($post->ID, 'secondaryTitle_value', true), 'post'); ?>
							    </h2>
					    		<?php
						    	$deep_output = ".present-container .secondaryTitle{color: #$stcolor; font-size: $stsize; margin-top:{$stmargin};letter-spacing: $titlesecletterspacing; line-height: $titleseclineheight; text-transform: $titlesectransform;}";
								deep_set_custom_inline_css($deep_output);
					    	}
		    			}
		    		?>

		    		</div>
		    		<?php
		    		if ($breadcrumbs == "on"){
			    		?>
			    		<div class="deep_breadcrumbs">
							<?php 
								deep_the_breadcrumb(); 
								$deep_output = ".deep_breadcrumbs{".esc_attr($bcaux)."}";
								deep_set_custom_inline_css($deep_output);
							?>
			    		</div>
			    		<?php
					}
					?>
				</div>
		<?php }
		?>
		</div>	
		<?php
	}

	$sidebar_scheme = get_post_meta($deep_thisPostID, 'sidebar_for_default_value', true);
	if (defined('DEEP_IS_FIRST_PAGE')) $sidebar_scheme = get_option('deep_blog_archive_sidebar');
	$sidebar = deep_convert_to_class(get_post_meta($deep_thisPostID, 'sidebars_available_value', true));
	if (!$sidebar) $sidebar = "defaultblogsidebar";
	
	$pageid = get_the_ID();
	switch ($sidebar_scheme){
		case "none":
			if (!defined("DEEP_IS_FIRST_PAGE") && $post->post_content != ""){
				?>
				<div class="content-before-blog container">
					<?php 
						deep_content_shortcoder($post->post_content);
						echo do_shortcode($post->post_content); 
					?>
				</div>
				<?php
			}
			?>
			<div class="blog-default wideblog">
				<div class="master_container">
					<section class="page_content col-xs-12 col-md-12">
						<div class="blog-default-bg">
							<div class="container">
							<?php deep_print_blog($pageid); ?>
							</div>
						</div>
					</section>
				</div>
			</div>
			<?php
		break;
		case "left":
			if (!defined("DEEP_IS_FIRST_PAGE") && $post->post_content != ""){
				?>
				<div class="content-before-blog container">
					<?php 
						deep_content_shortcoder($post->post_content);
						echo do_shortcode($post->post_content); 
					?>
				</div>
				<?php
			}
			?>
			<div class="blog-default blog-normal-with-sidebar">
				<div class="master_container container">
					<section class="page_content left sidebar col-xs-12 col-md-3">
						<div class="blog-sidebar-bg">
							<?php 
							if ($sidebar === "defaultblogsidebar") $sidebar = 'sidebar-widgets';
							if ( function_exists('dynamic_sidebar') && is_active_sidebar( $sidebar )) { 
								ob_start();
								do_shortcode(dynamic_sidebar($sidebar));
								$html = ob_get_contents();
								ob_end_clean();
								$html = wp_kses_no_null( $html, array( 'slash_zero' => 'keep' ) );
								$html = wp_kses_normalize_entities($html);
								echo wp_kses_hook($html, 'post', array());  
							} else get_sidebar();
							?>
						</div>
					</section>
					<section class="page_content right col-xs-12 col-md-9">
						<div class="blog-default-bg">
							<?php deep_print_blog($pageid); ?>
						</div>
					</section>
				</div>
			</div>
			<?php
		break;
		case "right":
			if (!defined("DEEP_IS_FIRST_PAGE") && $post->post_content != ""){
				?>
				<div class="content-before-blog container">
					<?php 
						deep_content_shortcoder($post->post_content);
						echo do_shortcode($post->post_content); 
					?>
				</div>
				<?php
			}
			?>
			<div class="blog-default blog-normal-with-sidebar">
				<div class="master_container container">
					<section class="page_content left col-xs-12 col-md-9">
						<div class="blog-default-bg">
							<?php deep_print_blog($pageid); ?>
						</div>
					</section>
					<section class="page_content right sidebar col-xs-12 col-md-3">
						<div class="blog-sidebar-bg">
							<?php 
							if ($sidebar === "defaultblogsidebar") $sidebar = 'sidebar-widgets';
							if ( function_exists('dynamic_sidebar') && is_active_sidebar( $sidebar )) { 
								ob_start();
								do_shortcode(dynamic_sidebar($sidebar));
								$html = ob_get_contents();
								ob_end_clean();
								$html = wp_kses_no_null( $html, array( 'slash_zero' => 'keep' ) );
								$html = wp_kses_normalize_entities($html);
								echo wp_kses_hook($html, 'post', array());  
							} else get_sidebar();
							?>
						</div>
					</section>
				</div>
			</div>
			<?php
		break;
		default:
			if (!defined("DEEP_IS_FIRST_PAGE") && $post->post_content != ""){
				?>
				<div class="content-before-blog container">
					<?php 
						deep_content_shortcoder($post->post_content);
						echo do_shortcode($post->post_content); 
					?>
				</div>
				<?php
			}
			?>
			<div class="blog-default wideblog">
				<div class="master_container">
					<section class="page_content col-xs-12 col-md-12">
						<div class="blog-default-bg">
							<div class="container">
							<?php deep_print_blog($pageid); ?>
							</div>
						</div>
					</section>
				</div>
			</div>
			<?php
		break;
	}

	function deep_print_blog($pageid){
		
		$pag = 1;
		global $wp_query;
		$pag = $wp_query->query_vars['paged'];
		if ($pag=="" && isset($wp_query->query['paged'])) $pag = $wp_query->query['paged'];
		
		$cattype = "category__in";
		if (strpos(get_post_meta($pageid, 'posts_filter_categories_value', true), ',') !== false){
			$categories = explode(',',get_post_meta($pageid, 'posts_filter_categories_value', true));	
		} else {
			$cattype = "cat";
			$categories = get_post_meta($pageid, 'posts_filter_categories_value', true);
		}
		$tagtype = "tag__in";
		if (strpos(get_post_meta($pageid, 'posts_filter_tags_value', true), ',') !== false){
			$tags = explode(",",get_post_meta($pageid, 'posts_filter_tags_value', true));	
		} else {
			$tagtype = "tag_id";
			$tags = get_post_meta($pageid, 'posts_filter_tags_value', true);
		}
		$authortype = "author__in";
		if (strpos(get_post_meta($pageid, 'posts_filter_authors_value', true), ',') !== false){
			$authors = explode(",",get_post_meta($pageid, 'posts_filter_authors_value', true));
		} else {
			$authortype = "author";
			$authors = get_post_meta($pageid, 'posts_filter_authors_value', true);
		}
		$orderby = get_post_meta($pageid, 'posts_filter_orderby_value', true);
		$order = get_post_meta($pageid, 'posts_filter_order_value', true);
		
		if (!isset($nposts)) $nposts = get_option('posts_per_page');
		$args = array(
			'showposts' => $nposts,
	    	'orderby' => $orderby,
	    	'order' => $order,
	    	$cattype => $categories,
	    	$tagtype => $tags,
	    	$authortype => $authors,
	    	'post_status' => 'publish',
	    	'paged' => $pag
	    );
	    	
	    global $post, $wp_query, $deep_the_query, $deep_import_fonts;
	    
	    $deep_the_query = new WP_Query( $args );
	    
	    $deep_animate_posts = get_option('deep_animate_posts_on_scroll', 'on') == 'on' ? true : false;

		$sidebar_scheme = get_post_meta($pageid, 'sidebar_for_default_value', true);
		if (defined('DEEP_IS_FIRST_PAGE')) $sidebar_scheme = get_option('deep_blog_archive_sidebar');
	
	    if ($deep_the_query->have_posts()){ 
	    ?> 
	    	<div class="post-listing<?php if ($deep_animate_posts) echo " deep-animate-posts "; ?>">
		    	
		    	<?php
				$titlefont = get_option('deep_blog_normal_title_font');
				if (is_array($titlefont)) $titlefont = ""; $deep_import_fonts[] = $titlefont;
				$titlefont = explode("|",$titlefont);
				$titlefont[0] = $titlefont[0]."', 'Arial', 'sans-serif";
				if (!isset($titlefont[1])) $titlefont[1] = "";
				$titlecolor = intval(get_option('deep_blog_normal_title_color'),10);
				$titlesize = get_option('deep_blog_normal_title_size');
				if (!is_null($titlesize)) $titlesize = str_replace(" ", "", $titlesize);
		    
			    while ($deep_the_query->have_posts()){
				    $deep_the_query->the_post();
				    $postid = get_the_ID();
				    
				    $post_classes = array();
				    if ($deep_animate_posts) $post_classes[] = "not-in-view";
				    ?>
				    
				    <article id="post-<?php esc_attr(the_ID()); ?>" <?php post_class($post_classes); ?>>
					    
					    <?php
						    $posttype = get_post_meta(get_the_ID(), 'posttype_value', true);
						    if (!$posttype || $posttype == "") $posttype = "image";
						    
						    switch($posttype){
					    		case "image":
					    		
					    			if (wp_get_attachment_url( get_post_thumbnail_id($postid))){
						    			
									?>
										
											<div class="featured-image">
												
												<a href="<?php echo esc_url(get_the_permalink()); ?>" title="<?php the_title_attribute(); ?>">
												<img alt="<?php the_title_attribute(); ?>" src="<?php echo esc_url(wp_get_attachment_url( get_post_thumbnail_id($postid))); ?>" title="<?php the_title_attribute(); ?>"/>
												<span class="post_overlay">
														<i class="fa fa-plus" aria-hidden="true"></i>
													</span>
												</a>
											</div>
									
										<?php 
									}
					    			
					    		break;

					    		case "slider": 
					    			
					    			$randClass = rand(0,1000);
									?>
										
										<div class="flexslider <?php echo esc_attr($posttype); ?>" id="<?php echo esc_attr($randClass); ?>">
											<ul class="slides">
												<?php
													$sliderData = get_post_meta($postid, "sliderImages_value", true);
													$slide = explode("|*|",$sliderData);
												    foreach ($slide as $s){
												    	if ($s != ""){
												    		$params = explode("|!|",$s);
												    		$attachment = get_post( $params[0] );
												    		$title = isset($attachment->post_excerpt) ? $attachment->post_excerpt : "";
												    		echo "<li>";
												    		echo "<img src='".esc_url($params[1])."' alt='".esc_attr($title)."' title='".esc_attr($title)."'>";
												    		echo "</li>";	
												    	}
												    }
												?>
											</ul>
										</div>
										
									<?php
										$deep_inline_script = '
											jQuery(document).ready(function(){
												"use strict";
												jQuery("#'.$randClass.'.flexslider").flexslider({
													animation: "'. esc_js( get_option('deep_posts_flex_transition', 'fade') ) .'",
													slideshow: '. esc_js( (get_option('deep_posts_flex_autoplay','on') == 'on') ? "true" : "false" ) .',
													slideshowSpeed: '. esc_js( get_option('deep_posts_flex_slide_duration','5500') ) .',
													animationSpeed: '. esc_js( get_option('deep_posts_flex_transition_duration','500') ) .',
													directionNav: '. esc_js( (get_option('deep_posts_flex_navigation','on') == 'on') ? "true" : "false" ) .',
													controlNav: '. esc_js( (get_option('deep_posts_flex_controls','on') == 'on') ? "true" : "false" ) .',
													smootheHeight:false,
													start: function(slider) {
													  slider.removeClass("loading").css("overflow","").find(".slides").css("max-height", "'.esc_js( intval(get_option('deep_posts_flex_height','400')) ).'px" );
													}
												});
											});
										';
										wp_add_inline_script('deep-global', $deep_inline_script, 'after');
					    		break;

					    		case "audio":
					    			
					    			?>
									<div class="audioContainer">
										<?php
											if (get_post_meta($postid, 'audioSource_value', true) == 'embed') echo get_post_meta($postid, 'audioCode_value', true); 
											else {
												$audio = explode("|!|",get_post_meta($postid, 'audioMediaLibrary_value', true));
												if (isset($audio[1])) {
													$ext = explode(".",$audio[1]);
													if (isset($ext)) $ext = $ext[count($ext)-1];
													?>
													<audio controls="controls"><source type="audio/<?php echo esc_attr($ext); ?>" src="<?php echo esc_url($audio[1]); ?>"></audio>
													<?php
												}
											}
										?>
									</div>
									<?php
					    		break;
					    		
					    		case "video":
					    			
					    			?>
					    			
					    			<div class="post-video <?php echo esc_attr(get_post_meta($postid, "videoSource_value", true)); ?>">
										<div class="video-thumb">
											<div class="video-wrapper vendor">
										<?php
											$videosType = get_post_meta($postid, "videoSource_value", true);
											if ($videosType != "embed"){
												$videos = get_post_meta($postid, "videoCode_value", true);
												$videos = preg_replace( '/\s+/', '', $videos );
												$vid = explode(",",$videos);
											}
											switch (get_post_meta($postid, "videoSource_value", true)){
												case "media":
													$video = explode("|!|",get_post_meta($postid, 'videoMediaLibrary_value', true));
													if (isset($video[1])) {
														$ext = explode(".",$video[1]);
														if (isset($ext)) $ext = $ext[count($ext)-1];
														?>
														<video controls="controls" class="video-controls"><source type="video/<?php echo esc_attr($ext); ?>" src="<?php echo esc_url($video[1]); ?>"></video>
														<?php
													}
												break;
												case "youtube":
													if (isset($vid[0])) echo "<iframe src='//www.youtube.com/embed/".esc_attr($vid[0])."' frameborder='0' allowfullscreen loading='lazy'></iframe>";
													break;
												case "vimeo":
													if (isset($vid[0])) echo '<iframe src="https://player.vimeo.com/video/'.esc_attr($vid[0]).'" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen loading="lazy"></iframe>';
													break;
											}						
										?>
											</div>
										</div>
									</div>
					    			
									<?php
					    		break;
					    		
					    		case "gallery":
						    		$slider = get_post_meta($postid,'gallery_slider_value',true);
									if ($slider != '-1'){
										
										if (substr($slider, 0, 10) === "revSlider_"){
											?>
											
											<div class="gallery_container">
												<?php
													if (!function_exists('putRevSlider')){
														echo esc_html__('Please install the missing plugin - Revolution Slider.', 'deep');
													} else {
														putRevSlider(substr($slider, 10));
													}
												?>
											</div>
											
											<?php
										} else {
											?>
											
											<div class="gallery_container">
												<?php
													if (!function_exists('masterslider')){
														echo esc_html__('Please install the missing plugin - MasterSlider.', 'deep');
													} else {
														echo do_shortcode( '[masterslider alias="'.substr($slider, 13).'"]' );
													}
												?>
											</div>
											
											<?php
										}
									}
					    		break;
					    		
					    		case "quote":
					    			?>
					    			<a href="<?php echo esc_url(get_the_permalink()); ?>">
						    			<div class="post-quote">
				                        	<blockquote><i class="fa fa-quote-left"></i> <?php echo wp_kses(get_post_meta($postid, 'quote_text_value', true), 'post'); ?> <i class="fa fa-quote-right"></i></blockquote>
				                        	<span class="author-quote">-- <?php echo wp_kses(get_post_meta($postid, 'quote_author_value', true), 'post'); ?> --</span>
				                        </div>
			                        </a>
					    			<?php
					    		break;

								case "link":
									?>
									<h2 class="post-title post-link">
										<?php
											$linkurl = get_post_meta($postid, 'link_url_value', true) != '' ? get_post_meta($postid, 'link_url_value', true) : get_permalink();
											$linktext = get_post_meta($postid, 'link_text_value', true) != '' ? get_post_meta($postid, 'link_text_value', true) : $linkurl;
										?>
										<a href="<?php echo esc_url($linkurl); ?>" target="_blank"><?php echo esc_html($linktext); ?></a>
			                        </h2>
									<?php
								break;
					    		
					    		case "text": default:
					    		
					    			if ($posttype != "text"){
						    			if (wp_get_attachment_url( get_post_thumbnail_id($postid))){
							    			
										?>
											
											<div class="featured-image">
												
												<a href="<?php echo esc_url(get_the_permalink()); ?>" title="<?php the_title_attribute(); ?>">
												<img alt="<?php the_title_attribute(); ?>" src="<?php echo esc_url(wp_get_attachment_url( get_post_thumbnail_id($postid))); ?>" title="<?php the_title_attribute(); ?>"/>
												<span class="post_overlay">
														<i class="fa fa-plus" aria-hidden="true"></i>
													</span>
												</a>
											</div>
												
										
											<?php 
										}
					    			}

					    		break;
				    		}
				    		?>
				    			<?php
								
								$deep_output = "#post-".$postid." .the_title h2{color: #$titlecolor; font-size: $titlesize; font-family: '{$titlefont[0]}'; font-weight: {$titlefont[1]};}";
								deep_set_custom_inline_css($deep_output);
						    
							    
					    		if ($posttype != "quote" && $posttype != "link"){
						    		?>
						    		
						    		<div class="the_title">
										<h2>
											<a href="<?php echo esc_url(get_the_permalink()); ?>"><?php echo wp_kses(get_the_title(), 'post'); ?></a>
										</h2>
									</div>
						    		<div class="blog_excerpt">
								    	<?php the_excerpt(); ?>
								    </div>
				    		<?php
				    			
							if ((isset($wp_query->queried_object->ID) && get_post_meta( $wp_query->queried_object->ID , 'boldway_single_display_metas_value' , true ) == "yes") || !isset($wp_query->queried_object->ID)){
								?>
								<div class="metas-container">
									<?php
						    			$metas = isset($wp_query->queried_object->ID) ? explode(",", get_post_meta( $wp_query->queried_object->ID , 'boldway_single_metas_value' , true )) : array("date,author,tags,categories");
						    			if (!empty($metas)){
							    			$firstMeta = true;
							    			foreach ($metas as $meta){
								    			switch ($meta){
									    			case "date":
										    			
									    				?>
									    				<p class="blog-date"><i class="mi-clock"></i><?php echo get_the_date(); ?></p>
									    				<?php
									    			break;
									    			case "author":
									    				
									    				?>
									    				<p class="deep-apply-tcolor"><a class="the_author" href="<?php echo get_author_posts_url( get_the_author_meta('ID') ); ?>"><i class="mi-user"></i><?php  esc_html(the_author_meta('display_name')); ?></a></p>
									    				<?php
									    			break;
									    			case "tags":
									    				$posttags = get_the_tags();
														if ($posttags) {
															
															$first = true;
															echo '<p class="deep-apply-tcolor"><i class="mi-folder"></i> ';
															
															foreach($posttags as $tag) {
																if ($tag->name != "uncategorized"){
																	if ($first){
																		echo "<a class='deep-apply-tcolor' href='".esc_url( get_term_link($tag) )."'>".esc_html($tag->name)."</a>"; 
																		$first = false;
																	} else {
																		echo "<span>, </span><a class='deep-apply-tcolor' href='".esc_url( get_term_link($tag) )."'>".esc_html($tag->name)."</a>";
																	}
																}
														  	}
														  	echo '</p>';
														}
									    			break;
									    			case "categories":
									    				$postcats = get_the_category();
														if ($postcats) {
															
															$first = true;
															echo '<p class="deep-apply-tcolor"><i class="mi-folder"></i> ';
															
															
															foreach($postcats as $cat) {
																if ($cat->name != "uncategorized"){
																	if ($first){
																		echo "<a class='deep-apply-tcolor' href='".esc_url( get_term_link($cat) )."'>".esc_html($cat->name)."</a>"; 
																		$first = false;
																	} else {
																		echo "<span>, </span><a class='deep-apply-tcolor' href='".esc_url( get_term_link($cat) )."'>".esc_html($cat->name)."</a>"; 
																	}	
																}
														  	}
														  	echo '</p>';
														}
									    			break;
									    			case "comments":
									    				
									    				echo '<p class="deep-apply-tcolor"><i class="mi-message"></i> ';
									    				echo get_comments_number();
									    				echo '</p>';
									    			break;
									    			
								    			}
							    			}
						    			}
					    			?>
					    		</div>
								<?php
							}
							?>
							
							
					    		<?php
				    		}
				    		
				    		
				    		
						?>
					    <div class="divider-posts"></div>
				    </article>
				    <?php
			    }
			    
			    ?>
	    	</div>
	    	<div class="navigation">
				<?php
					$deep_reading_option = get_option('deep_blog_reading_type');
					wp_reset_postdata();
					if ($deep_reading_option != "paged" && $deep_reading_option != "dropdown"){ 
						if (function_exists('icl_t')){
							next_posts_link( '<div class="next-posts"><i class="fa fa-angle-left"></i>'.sprintf(esc_html__("%s", "deep"), icl_t( 'deep', 'Previous posts', get_option('deep_previous_text'))).'</div>', $deep_the_query->max_num_pages);  
							previous_posts_link('<div class="prev-posts">'.sprintf(esc_html__("%s", "deep"), icl_t( 'deep', 'Next posts', get_option('deep_next_text'))).'<i class="fa fa-angle-right"></i></div>', $deep_the_query->max_num_pages);
						} else {
							next_posts_link( '<div class="next-posts"><i class="fa fa-angle-left"></i>'.sprintf(esc_html__("%s", "deep"), get_option("deep_previous_text")).'</div>', $deep_the_query->max_num_pages);  
							previous_posts_link('<div class="prev-posts">'.sprintf(esc_html__("%s", "deep"), get_option("deep_next_text")).'<i class="fa fa-angle-right"></i></div>', $deep_the_query->max_num_pages);
						}
					} else {
						deep_wp_pagenavi();
					}
				?>	
			</div>
	    <?php
		    
		    if ($deep_animate_posts){
			    $animate_posts_script = '
			    	jQuery(".not-in-view").waypoint({
						handler: function(event, direction){
							var element = this.element ? this.element : this;
							jQuery(element).removeClass("not-in-view");
						},
						offset: "80%"
					});
			    ';
			    wp_add_inline_script('deep-global', $animate_posts_script, 'after');
		    }
		    
		}
	}
	
	?>
	
<?php get_footer(); ?>