<?php get_header(); ?>
<?php the_post(); ?>

<?php if ( get_theme_mod( 'kktfwp_blog_sidebar' ) === 'left' && ! get_theme_mod( 'kktfwp_blog_single', 0 ) ) {
		$position = 'left';
		$content_position = 'right';
	} else if ( get_theme_mod( 'kktfwp_blog_sidebar' ) === 'right' && ! get_theme_mod( 'kktfwp_blog_single', 0 ) ) {
		$position = 'right';
		$content_position = 'left';
	} else if ( get_theme_mod( 'kktfwp_blog_single', 0 ) || get_theme_mod( 'kktfwp_blog_sidebar' ) === 'full' ) {
		$position = 'full';
		$content_position = 'none';
	} else {
		$position = 'right';
		$content_position = 'left';
	}	
?>

<?php $title_type = kktfwp_title_type(); ?>

<?php if ( post_password_required( $post ) ) { 

		get_template_part( 'password-form' );
		
	} else { ?>
			
	<!-- start content wrapper -->			
	<div class="content">

		<?php if( $title_type == 'parallax' ) : ?>
		
		<div id="kk-parallax-wrapper" class="kk-parallax-wrapper">
			
			<?php echo kktfwp_parallax(); ?>

			<div id="kk-parallax-title-wrapper" class="kk-parallax-title-wrapper">
				<div id="kk-parallax-title" class="page-title">
					<?php $source = rwmb_meta( 'kk_customTitle', false, kktfwp_postid() );						
					if ( $source ) : ?>						
						<?php echo wp_kses( rwmb_meta( 'kk_customdescription', false, kktfwp_postid()), kktfwp_kses_allowed_args()) ?>						
					<?php else: ?>					
						<?php the_title( '<h1>', '</h1>' ); ?>							
					<?php endif; ?>
					<?php get_template_part( 'formats/single-post/post-meta' ); ?>
				</div>
			</div>	
			
			<a id="kk-down" class="kk-down is-loading" href="#kk-to-me"></a>
		
		</div>	

		<?php endif; ?>
		
		<div class="content-inner-wrapper clearfix">
		<span id="kk-to-me"></span>
		<?php if( $title_type == 'default' ) : ?>
		
			<div class="post-title">
				<h1><?php the_title(); ?></h1>
				
				<?php get_template_part( 'formats/single-post/post-meta' ); ?>
			</div>	

			<div class="divider clear"></div>	
			
		<?php endif; ?>
				
			<div class="inner-content" id="<?php echo esc_attr($content_position) ?>">
			
				<?php 
					$format = get_post_format();
					if( false === $format ) { $format = 'standard'; }
					get_template_part( 'formats/single-post/' . $format.'-single' );
				?>
				
				<?php if( $format == 'quote' ): ?>
				
				<?php $quoteLink = get_post_meta($post->ID, '_post_quote_source_value', true); ?>
			
					<h2 class="quote-text">
						&ldquo;<?php echo get_post_meta($post->ID, '_post_quote_value', true); ?>&rdquo;
					</h2>
					
					<?php if ($quoteLink!="") {?>
					<span class="quote-source">
						&mdash;&nbsp;<?php echo esc_url($quoteLink) ?>
					</span>
					<?php } ?>
				
				<?php else: ?>
				
				<div class="post-entry">
					<?php the_content(); ?>
					
					<?php 
					wp_link_pages( array(
						'before'      => '<div class="page-links"><span class="page-links-title">' . esc_html__( 'Pages:', 'toppic' ) . '</span>',
						'after'       => '</div>',
						'link_before' => '<span>',
						'link_after'  => '</span>',
						'pagelink'    => '<span class="screen-reader-text">' . esc_html__( 'Page', 'toppic' ) . ' </span>%',
						'separator'   => '<span class="screen-reader-text">, </span>',
					) );
					?>
				</div>
				
				<?php endif; ?>
				
				<?php if(has_tag()) : ?>
				<div class="post-tags">
					<h4><?php esc_html_e( 'Tags:', 'toppic' ); ?></h4>
					<?php the_tags('',''); ?>
				</div>
				<?php endif; ?>

				<?php 
					// If comments are open or we have at least one comment, load up the comment template
					if ( comments_open() || get_comments_number() ) {
						comments_template();
					} 
				?>
			</div>	
			
			<!-- start widgets -->
			<?php if ( ! get_theme_mod( 'kktfwp_blog_single', 0 ) && get_theme_mod( 'kktfwp_blog_sidebar' ) !== 'full' )  : ?>
				<?php if( is_active_sidebar( "kk-blog-sidebar" ) ) : ?> 
					<div class="sidebar" id="<?php echo esc_attr( $position ) ?>">
						<?php dynamic_sidebar("kk-blog-sidebar")?>		
					</div>
				<?php endif;?>
			<?php endif;?>
			<!-- end widgets -->
					
		</div>
		
		<?php get_template_part('extends/footer-area') ?>	
		
	</div>
	<!-- end content wrapper -->
<?php } ?>
			
<?php get_footer(); ?>