<?php
get_header(); 
?>
<div class="container">
	<div class="row">
		<div class="col-md-12">
			<div class="wrap-content-area">
				<div id="primary" class="content-area">	
					<main id="main" class="main-content" role="main">
						<div class="entry-content">	
							<?php while ( have_posts() ) : the_post(); ?>
								<div class="featured-post"><?php the_post_thumbnail('themesflat-portfolio-image-single'); ?></div> 

								<?php if ( themesflat_get_opt('portfolios_featured_title') != '' ): ?>
								<h1 class="post-title"><?php the_title(); ?></h1>
								<?php endif; ?>

								<div class="meta-post">
									<div class="inner-meta-post">
										<div class="meta-post-item meta-post-category">
											<span class="meta-post-title"><?php esc_html_e('Category :','themesflat') ?></span>
											<span class="meta-post-content"><?php echo esc_attr ( the_terms( get_the_ID(), 'portfolios_category', '', ', ', '' ) ); ?></span>
										</div>

										<?php if (themesflat_get_opt_elementor('portfolio_post_clients') != ''): ?>
										<div class="meta-post-item meta-post-clients">
											<span class="meta-post-title"><?php esc_html_e('Clients :','themesflat') ?></span>
											<span class="meta-post-content"><?php echo themesflat_get_opt_elementor('portfolio_post_clients'); ?></span>
										</div>
										<?php endif; ?>

										<div class="meta-post-item meta-post-date">
											<span class="meta-post-title"><?php esc_html_e('Date :','themesflat') ?></span>
											<span class="meta-post-content"><?php echo esc_attr( the_date() ); ?></span>
										</div>

										<?php if (themesflat_get_opt_elementor('portfolio_post_location') != ''): ?>
										<div class="meta-post-item meta-post-location">
											<span class="meta-post-title"><?php esc_html_e('Location :','themesflat') ?></span>
											<span class="meta-post-content"><?php echo themesflat_get_opt_elementor('portfolio_post_location'); ?></span>
										</div>
										<?php endif; ?>
									</div>
								</div>
								<?php the_content();?>
							<?php endwhile; // end of the loop. ?>
						</div><!-- ./entry-content -->
					</main><!-- #main -->
				</div><!-- #primary -->
			</div>
		</div>
	</div>
</div>

<?php if ( themesflat_get_opt( 'portfolios_show_post_navigator' ) == 1 ): ?>
<!-- Navigation  -->
<div class="container">
	<div class="row">
		<div class="col-lg-12"><?php themesflat_post_navigation(); ?></div>
	</div>			
</div>	
<?php endif; ?>

<!-- Related -->
<?php if ( themesflat_get_opt( 'portfolios_show_related' ) == 1 ) { ?>
	<div class="container">
	<?php		
		$grid_columns = themesflat_get_opt( 'portfolios_related_grid_columns' );
		$layout =  'portfolios-grid';

		if ( get_query_var('paged') ) {
		    $paged = get_query_var('paged');
		} elseif ( get_query_var('page') ) {
		    $paged = get_query_var('page');
		} else {
		    $paged = 1;
		}

		$terms = get_the_terms( $post->ID, 'portfolios_category' );
		if ( $terms != '' ){
			$term_ids = wp_list_pluck( $terms, 'term_id' );
			$args = array(
				'post_type' => 'portfolios',
				'posts_per_page'      => -1,
				'tax_query' => array(
					array(
					'taxonomy' => 'portfolios_category',
					'field' => 'term_id',
					'terms' => $term_ids,
					'operator'=> 'IN'
					)),
				'posts_per_page'      => themesflat_get_opt( 'number_related_post_portfolios' ),
				'ignore_sticky_posts' => 1,
				'post__not_in'=> array( $post->ID )
			);

			if ( $layout != '' ) {
			    $class[] = $layout;
			}
			if ( $grid_columns != '' ) {
			    $class[] = 'column-' . $grid_columns ;
			}
			
			?>
			<div class="related-post related-posts-box">
			    <div class="box-wrapper">
			        <div class="box-title">
			        	<h6 class="sub-title"><?php esc_html_e( "Related Portfolio", 'themesflat' ) ?></h6>
			        	<h2 class="title"><?php esc_html_e( "Let's See Some Portfolio", 'themesflat' ) ?></h2>	
		        	</div>
			        
			        <div class="themesflat-portfolios-taxonomy">			            
		            	<div class="<?php echo esc_attr( implode( ' ', $class ) ) ?> wrap-portfolios-post row">
				            <?php 
				            $query = new WP_Query($args);
				            if( $query->have_posts() ) {
				                while ( $query->have_posts() ) : $query->the_post(); ?>           
				                    <div class="item">
				                        <div class="portfolios-post portfolios-post-<?php the_ID(); ?>">
				                            <div class="featured-post">
				                            	<a href="<?php echo get_the_permalink(); ?>">
				                                <?php 
				                                    if ( has_post_thumbnail() ) { 
				                                        $themesflat_thumbnail = "themesflat-portfolio-image";                              
				                                        the_post_thumbnail( $themesflat_thumbnail );
				                                    }                                           
				                                ?>
				                                </a>
				                            </div>
				                            <div class="content">
				                            	<div class="inner-content">
				                                    <h2 class="title">
				                                         <a href="<?php echo get_the_permalink(); ?>"><?php echo get_the_title(); ?></a>
				                                    </h2>
				                                    <?php if (themesflat_get_opt_elementor('portfolio_post_position') != ''): ?>
				                                    <div class="post-meta">
			                                            <?php echo themesflat_get_opt_elementor('portfolio_post_position'); ?>
				                                    </div>
				                                    <?php endif; ?>
			                                    </div>				                                
				                            </div>
				                        </div>
				                    </div>                    
				                    <?php 
				                endwhile; 
				            }
				            wp_reset_postdata();
				            ?>            
				        </div>			            
			        </div>
			    </div>
			</div>
		<?php } ?>
	</div>	
<?php } ?>

<?php get_footer(); ?>