<?php get_header();?>


<!-- section -->
<section>

	<?php if (have_posts()): while (have_posts()): the_post();?>

	<!-- article -->
			<article id="post-<?php the_ID();?>" <?php post_class();?>>

				<!-- post thumbnail -->
				<?php if (has_post_thumbnail()): // Check if Thumbnail exists ?>
					<div class="thumbnailwrapper">
						<?php the_post_thumbnail(); // Fullsize image for the single post ?>
					</div>

				<?php endif;?>
				<!-- /post thumbnail -->

				<div class="titlewrapper">
					
					<div class="metadata">
						<?php if (!is_page()): ?>
							<div class="metaWrapper">
								<div class="time-cat">
									<?php the_time('Y. m. d.');?> |
									<?php the_category(' | ');?>
								</div>
								<div class="format">
								<?php 
									$terms = get_the_terms( $post->ID, 'Format' );
									if ($terms && ! is_wp_error( $terms )) {
										foreach($terms as $term) {
											?>
											<a href="<?php echo esc_url(get_term_link( $term));?>">
											<?php
											echo $term->name;
											echo '</a>';
										} 
									} ?>
								</div>
							</div>
							
						<?php endif; ?>
					</div>					
					<h1 class="single-title">
						<?php the_title();?>
					</h1>

				</div>
				<!-- /post title -->
				
				<div class="single-content">
					<?php if (!is_page()): ?>
						<hr class="content-wrap content-begin">
					<?php endif; ?>
					<?php the_content(); // Dynamic Content ?>
						
					<?php 
						$terms = get_the_terms( $post->ID, 'Writer' );
						if ($terms && ! is_wp_error( $terms )) {
    				?>
							<p class="authors">Szerző: 
							<?php
								foreach($terms as $term) {
									?>
									<a href="<?php echo esc_url(get_term_link( $term));?>">
									<?php echo $term->name; ?>
									</a>
									<?php
								} 
								echo '<p>';
						} ?>
							
					<hr class="content-wrap content-end">
				</div>

				<!-- Related articles -->
				<?php 
					$orig_post = $post;
					global $post;
					$categories = get_the_category($post->ID);
			
					if ($categories) {
						$category_ids = array();
						
						foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;
							$args=array(
								'category__in' => $category_ids,
								'post__not_in' => array($post->ID),
								'posts_per_page'=> 3, // Number of related posts that will be shown.
								'caller_get_posts'=>1,
								'related_loop'=>true
							);

						$my_query = new wp_query( $args );
						//console_debug($my_query);
						if( $my_query->have_posts() ) {
							?>
							<div id="related_posts"><h3><?php _e('More posts:', 'dis2019');?></h3><ul>
							<?php
							while( $my_query->have_posts() ) {
								$my_query->the_post();
								static $relatedloop = true;
								?>
						
								<li>
									<div class="relatedWrapper">
										<?php include( locate_template( 'loop-inner.php', false, false ) ); ?>
									</div>
									
								</li>
								<?php
							}
							echo '</ul></div>';
						}
					};
					$post = $orig_post;
					wp_reset_query(); ?>
				
				<div class="toHome">
					<a href="<?php echo esc_url( home_url( '/' ) ); ?>">
						← <?php _e('Back to home:', 'dis2019');?>
					</a>
					<hr class="related-wrap single-end">
				</div>
				
				

			</article>
			<!-- /article -->

	

			<?php endwhile;?>

			

		<?php else: ?>

	<!-- article -->
	<article>

		<h1><?php _e('Sorry, nothing to display.', 'dis2019');?></h1>

	</article>
	<!-- /article -->

	<?php endif;?>

	

	
</section>
<!-- /section -->

		


<?php get_footer();?>