<?php get_header(); 

	get_template_part('partials/template', 'hero'); 

    $download = get_field('download'); ?>

<section class="page-section main-content-section">
	<div class="container">
				<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

					<?php if (get_post_type() == "news" or get_post_type() == "media" or get_post_type() == "faq"): ?>

						<div class="singular-header">
							<div class="hide-on-med-and-up single-header-post-type">
									<?php 
									$postType = get_post_type_object(get_post_type());
									if ($postType) {
									    echo esc_html($postType->labels->all_items);
									}
									?>
							</div>
							<a href="<?php echo get_post_type_archive_link( get_post_type() ); ?>" class="control control-back inverse icon-arrow-thin-left">
		                        <span>Back</span>
		                    </a>


							<span class="date"><?php echo get_the_date(); ?></span>

							<?php get_template_part('partials/template', 'post-meta'); ?>
						</div>

						<h1 class="center-align"><?php the_title(); ?></h1>

						<div class="single-post-feature-image nospace-mobile">
							<?php the_post_thumbnail();?>
						</div>
					<?php endif; ?> 

		<div class="row">

			<div class="col s12 m10 push-m1 l8 push-l2">

						
						<div class="index-content <?php if (isset($download) OR '' !== get_post()->post_content ) { echo ' has_content'; } ?>">
							<?php the_content(); ?>


							<?php if (isset($download)): ?>
								<a class="btn-color btn" target="_none" href="<?php echo $download['url']; ?>">
								    <?php echo file_get_contents(get_template_directory() . '/assets/img/download.svg'); ?> Download 
								</a>
							<?php endif; ?>

						</div>


					<?php if (get_post_type() == "post"): ?>
						<?php //comments_template(); ?>
					<?php endif; ?> 

				<?php endwhile; else : ?>
					<p><?php _e( 'Sorry, nothing was found.' ); ?></p>
				<?php endif; ?>

			</div>


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

<?php $panels = get_field('panel_environment_201703131208b_panels'); ?>
<?php if ($panels): ?>

	<?php if( have_rows('panel_environment_201703131208b_panels') ): ?>
	    <section class="page-section clearfix ">
	    <?php while( have_rows('panel_environment_201703131208b_panels') ): the_row(); 
	        $panels_title = get_sub_field('panels_title');
	        $panels_label = get_sub_field('panels_label');
	        $panels_content = get_sub_field('panels_content');
	        $panels_button = get_sub_field('panels_button');
	        ?>
	        	<div class="section-inner plain_text">
	        		<div class="container">

	        			<div class="wysiwyg">
	        				<h2 class="section-title">
	        					<?php echo $panels_title; ?>
	        				</h2>
	        				<?php echo $panels_content; ?>
	        				<?php echo $panels_button; ?>
	        			</div>
	        		</div>
	        	</div>
	    <?php endwhile; ?>
	    </section>
	<?php endif; ?>

<?php endif; ?>



<?php if (get_post_type() == "news" or get_post_type() == "media"): ?>


	<!-- begin custom related loop, isa -->
	 
	<?php 
	global $post;
	$post_type = get_post_type();
	// arguments
	$args = array(
	'post_type' => $post_type,
	'posts_per_page' => 4,
	'post__not_in' => array ($post->ID)
	);
	$related_items = new WP_Query( $args );
	// loop over query
	if ($related_items->have_posts()) : ?>


		<section class="page-section related-posts style-med clearfix">
			<div class="section-inner card_grid">
			<div class="container">
				<h2 class="center-align section-title">Related <?php echo esc_html($postType->labels->all_items) ?></h2>
				<div class="posts-grid">
						<?php while ( $related_items->have_posts() ) : $related_items->the_post();
						?>
							<?php get_template_part('partials/template', 'post-card'); ?>
						<?php
						endwhile;
					?>
					 
				</div>
			</div>
			</div>
		</section>

	<?php endif;
	// Reset Post Data
	wp_reset_postdata();
	?>
	 
<?php endif; ?>

<?php

	get_template_part('partials/template', 'pagesections'); 
?>


<?php get_footer(); ?>