<?php

// Prevent Direct Access
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

$background = get_theme_mod('blog_top_background');

$show_author = get_theme_mod('blog_single_show_author', true);
$show_date = get_theme_mod('blog_single_show_date', true);
$show_categories = get_theme_mod('blog_single_show_categories', true);
$show_tags = get_theme_mod('blog_single_show_tags', true);
$show_end_categories = get_theme_mod('blog_single_show_end_categories', false);
$show_end_tags = get_theme_mod('blog_single_show_end_tags', false);
$end_categories_title = get_theme_mod('blog_single_end_categories_title', esc_html__('Categories', 'maxo-fa'));
$end_tags_title = get_theme_mod('blog_single_end_tags_title', esc_html__('Tags', 'maxo-fa'));

get_header();

while( have_posts() ){

the_post();
?>

<section id="page_header" class="page-header padding_top" <?php if($background){ echo 'style="background-image:url('.wp_get_attachment_url($background).');"'; } ?>>
	<div class="container header_content padding_top">
		<div class="row">
			<div class="col-sm-12">

				<?php echo '<h1 class="whitecolor bottom25"><a href="'.get_permalink( get_option('page_for_posts') ).'">'.esc_html__('Blog', 'maxo-fa').'</a></h1>'; ?>

			</div>
		</div>
	</div>
</section>

<section id="ourblog" class="padding_bottom padding_top_half">
	<div class="container">
		<div class="row">

			<?php
			if( is_active_sidebar('sidebar') ){
				$content_class = 'col-md-8 col-sm-8';
				$img_size = 'blog';
			}
			else{
				$content_class = 'col-xs-12';
				$img_size = 'blog_wide';
			}
			?>

			<div class="<?php echo $content_class ?> padding_top_half">
				
				<div class="blog_item">
					
					<?php if( has_post_thumbnail() ){ ?>
					<div class="image">
						<?php the_post_thumbnail($img_size) ?>
					</div>
					<?php } ?>
					
					<?php if( $show_author || $show_date || ($show_categories && has_category()) || ($show_tags && has_tag()) ){ ?>
					<div class="blog_author flat top20">
					
						<?php if( $show_author ){ ?>
						<span class="photo_container"><?php echo get_avatar( get_the_author_meta('ID'), 36 ); ?></span>
						<div class="authorname"><a href="<?php echo get_author_posts_url( get_the_author_meta('ID') ) ?>"><?php the_author() ?></a></div>
						<?php } ?>
						
						<?php if( $show_date ){ ?>
						<p class="metas"> <i class="fa fa-calendar"></i> <span><?php the_time('j F Y') ?></span> </p>
						<?php } ?>

						<?php if( $show_categories && has_category() ){ ?>
						<p class="metas"> <i class="fa fa-folder-open"></i> <span><?php the_category(esc_html_x(',', 'separator', 'maxo-fa').' ') ?></span> </p>
						<?php } ?>

						<?php if( $show_tags && has_tag() ){ ?>
						<p class="metas"> <i class="fa fa-tags"></i> <span><?php the_tags('', esc_html_x(',', 'separator', 'maxo-fa').' ', '') ?></span> </p>
						<?php } ?>
						
					</div>
					<?php } ?>
					
					<h3 class="top40 darkcolor bottom25"><?php the_title() ?></h3>

					<?php the_content() ?>

					<?php if( $show_end_categories && has_category() ){ ?>
					<div class="post-info"><?php echo $end_categories_title ?>: <?php the_category( ' '.esc_html_x(',', 'separator', 'maxo-fa').' ' ) ?></div>
					<?php } ?>
					
					<?php if( $show_end_tags && has_tag() ){ ?>
					<div class="post-info"><?php echo $end_tags_title ?>: <?php the_tags( '', ' '.esc_html_x(',', 'separator', 'maxo-fa').' ' ) ?></div>
					<?php } ?>
					
				</div>
				
				<?php
				if(get_post_type() == 'post'){
					comments_template();
				}
				?>
				
			</div>
			
			<?php get_sidebar(); ?>
			
		</div>
	</div>
</section>

<?php
}

get_footer();