<?php

$single_blog_sidebar = aidoo_get_options('nbcore_blog_sidebar');
$title_position = aidoo_get_options('nbcore_blog_single_title_position');
$title_blog_single_bg = aidoo_get_options('nbcore_blog_bg_single_title');
if($title_blog_single_bg){
	$title_bg = wp_get_attachment_image_src( $title_blog_single_bg,'full' );
}
get_header();
    if('position-1' === $title_position && aidoo_get_options('show_title_section')) {
		$bg_title_class 		= isset($title_bg[0]) ? ' bg_title_single_post bg_img' : '';
		$bg_title_inline_css 	= isset($title_bg[0]) ? ' style="background-image: url(' . esc_url($title_bg[0]) . ')"' : '';
        echo '<div class="nb-page-title-wrap' . esc_attr($bg_title_class) . '"' . $bg_title_inline_css . '><div class="container"><div class="nb-page-title">';
        aidoo_posted_on();
		the_title( '<h1 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h1>' );
        echo '</div></div></div>';
    } ?>
	<div class="container layout-content">
		<div class="single-blog row <?php aidoo_blog_classes(); ?>">

			<div id="primary" class="content-area">
				<main id="main" class="site-main" role="main">

				<?php
				aidoo_setPostViews(get_the_ID());
				while ( have_posts() ) : the_post(); ?>
					<div class="entry-content">
                        <?php
                        if(aidoo_get_options('nbcore_blog_single_show_thumb')):
                            $thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full' );
                        	if($thumb):
                            ?>
                            <div class="entry-image">
								<?php
								echo '<div class="bg_thumb" style="background-image:url('.$thumb[0].')"></div>';
								?>
                            </div>
                        <?php endif;
						endif; ?>
						<div class="entry-content">
							<?php if('position-2' === $title_position) {
								aidoo_get_categories();
								the_title( '<h1 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h1>' );
								aidoo_posted_on();
							}?>
						</div>
						<div class="entry-line">
						<div class="entry-text">
							<?php
							the_content( sprintf(
							/* translators: %s: Name of current post. */
								wp_kses( esc_html__( 'Continue reading %s <span class="meta-nav">&rarr;</span>', 'aidoo' ), array( 'span' => array( 'class' => array() ) ) ),
								the_title( '<span class="screen-reader-text">"', '"</span>', false )
							) );

							wp_link_pages( array(
								'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'aidoo' ),
								'after'  => '</div>',
							) );
							?>
						</div>

						<div class="single-post-cat-list">
							<span><?php echo esc_html__('Categories: ', 'aidoo');?></span>
							<?php echo get_the_category_list(', '); ?>
						</div>
						<?php if(has_tag()):?>
							<div class="single-post-tag-list">
								<span><?php echo esc_html__('Tags: ', 'aidoo');?></span>
								<?php echo get_the_tag_list('', ', ', ''); ?>
							</div>
						<?php endif;?>
						<?php
                        if('inside-content' === aidoo_get_options('share_buttons_position')) {
                            if(aidoo_get_options('nbcore_blog_single_show_social') && function_exists('nbcore_share_social')) {
								?>
									<div class="social">
										<?php esc_html_e('Share:', 'aidoo'); ?><?php nbcore_share_social(); ?>
									</div>
								<?php
                            }
                        }
						?>
						</div>
						<?php if(aidoo_get_options('nbcore_blog_single_show_nav')): 
							$nextPost = get_next_post(true);
							$prevPost = get_previous_post(true);
							if(!empty($nextPost) || !empty($prevPost)){
							?>
								<nav class="single-blog-nav" role="navigation">
								<?php
								if($prevPost != null) {
									$thumb = '';
									$prevthumbnail = get_the_post_thumbnail($prevPost->ID, array(100,100) );
									if(!empty($prevthumbnail)){
										$thumb = '<span class="thumb">'.$prevthumbnail.'</span>';
									}
									previous_post_link( '<div class="prev">%link<span></span></div>', _x( $thumb.'<h3 class="navi"><span>Previous post</span>%title</h3>', 'Previous post','aidoo' ) );
								}
								if($nextPost != null) {
									$thumb = '';
									$nextthumbnail = get_the_post_thumbnail($nextPost->ID, array(100,100) );
									if(!empty($nextthumbnail)){
										$thumb = '<span class="thumb">'.$nextthumbnail.'</span>';
									}
									next_post_link( '<div class="next">%link<span></span></div>', _x( '<h3 class="navi"><span>Next post</span>%title</h3>'.$thumb, 'Next post', 'aidoo' ) );
								}
								?>
								</nav><!-- .single-nav -->
							<?php 
							}
						endif; 
						
						$author_meta = esc_html( get_the_author_meta( 'display_name' ) );
						$author_desc = get_the_author_meta('user_description');
						if(aidoo_get_options('nbcore_blog_single_show_author')):
							if($author_desc): ?>
							<div class="entry-author-wrap">
								<h3 class="entry-heading"><span><?php echo esc_html('About Author','aidoo') ?></span></h4>
								<div class="entry-author">
									<div class="author-image">
										<?php echo get_avatar(get_the_author_meta('ID'), 165); ?>
									</div>
									<div class="author-meta">
										<div class="author-name">
											<?php echo esc_html($author_meta); ?>
										</div>
										<div class="author-description">
											<?php echo esc_html($author_desc); ?>
										</div>
										<?php if(function_exists('nbcore_user_social')):?>
											<div class="social">
												<?php nbcore_user_social(); ?>
											</div>
										<?php endif;?>
									</div>
								</div>
							</div>
							<?php endif;
						endif; ?>
					

					<?php
					$args = array(
						'posts_per_page'    => 3,
						'post_type' => 'post',
						'ignore_sticky_posts' => 1
					);

					// The Query
					$the_query = new WP_Query( $args );
					if ( $the_query->have_posts() ) {?>
						<div class="entry-recent">
							<h3 class="entry-heading"><span><?php esc_html_e('Related Posts', 'aidoo');?></span></h3>

							<div class="related-post-wrap">
								<?php while ( $the_query->have_posts() ) {
									$the_query->the_post();
									if (has_post_thumbnail())
										$thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large');
									?>
									<div class="item">
										<?php if(isset($thumb[0])):?>
											<a href="<?php echo esc_url( get_permalink($post->ID) );?>">
												<img src="<?php echo esc_url( $thumb[0] );?>" />
											</a>
										<?php endif;?>
										<?php aidoo_get_categories(); ?>
										<h3><a href="<?php echo esc_url( get_permalink($post->ID) );?>"><?php echo esc_attr($post->post_title);?></a></h3>
									</div>
									<?php
								}?>
							</div>
						</div>
						<?php
					}
					wp_reset_postdata();
                    if(aidoo_get_options('nbcore_blog_single_show_comments')) {
                        if ( comments_open() || get_comments_number() ) {
							echo '<h3 class="entry-heading"><span>' . esc_html__('Comment', 'aidoo') . '</span></h3>';
                            comments_template();
                        }
                    }
					?>
					</div>
				<?php
				endwhile; // End of the loop.
				?>
				
				</main><!-- #main -->
			</div><!-- #primary -->
		<?php
        if('no-sidebar' !== $single_blog_sidebar) {
            get_sidebar();
        }
		?>
		</div>
	</div>
		

<?php
get_footer();
