<?php get_header(); ?>
<?php setPostViews(get_the_ID()); ?>
<?php 
	// get the current taxonomy term
	$category = get_the_category(); 
	// vars
	$color = get_field('color', $category[0]);
?>

	<div class="content inner single-post single-cat-<?php echo $category[0]->slug; ?>">
		<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
			<article id="post-<?php the_ID(); ?>" class="post">
				<?php $postID = get_the_ID(); ?>
				<header class="info">
					<div class="thumb container" style="background-color:<?php echo $color; ?>;">
						<?php if(has_post_thumbnail()): ?>
							<?php the_post_thumbnail( 'thumb-post' ); ?>
						<?php endif; ?>
					</div><!-- .thumb -->
					
					<div class="meta container">
						
						<style>
							
							@media only screen and (min-width: 1024px) {
								.single a:hover{
									color: <?php echo $color; ?>;
								}
								.single .bt-category:hover{
									background-color: <?php echo $color; ?> !important;
								}
								.single .wp-block-button__link:hover,
								.single .share .addtoany_list a:hover{
									background-color: <?php echo $color; ?> !important;
								}		
							}
							@media only screen and (max-width: 767px) {
								.single .wp-block-button__link,
								.single .share .addtoany_list a{
									background-color: <?php echo $color; ?> !important;
								}		
							}
						</style>

						<div class="dados">
							<a href="<?php echo get_category_link($category[0]->term_id); ?>" class="bt-category bg-cat-<?php echo $category[0]->slug; ?>"><?php echo $category[0]->cat_name; ?></a>
							<?php
								$terms = get_the_terms( $post->ID, 'countries' );
							?>
                            <div class="component-dados">
								<span class="local"><?php echo $terms[0]->name; ?></span>
								<span>|</span>
								<span class="data"><?php the_time('M'); ?> <?php the_time('j'); ?>, <?php the_time('Y'); ?></span> 
							</div>
                        </div>

						<h1 class="titlePost"><?php the_title(); ?></h1>

						<div class="author">
							<div class="photo">
								<img src="<?php the_field('photo', 'user_'.get_the_author_meta('ID')); ?>" alt="<?php echo get_the_author_meta('first_name'); ?> <?php echo get_the_author_meta('last_name'); ?>">
							</div>
							<div class="name">
								<p><b><?php echo get_the_author_meta('first_name'); ?> <?php echo get_the_author_meta('last_name'); ?> /</b>  Our Today</p>
								<span><?php $user_info = get_userdata(get_the_author_meta('ID')); echo implode(', ', $user_info->roles) . "\n";?></span>
								
							</div>
							<div class="share shareHeader">
								<button class="bt-share">
									<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 40 40">
										<g fill="none" fill-rule="evenodd">
											<g fill="<?php echo $color; ?>" class="bg-share">
												<g>
													<path d="M38 0c1.105 0 2 .895 2 2v36c0 1.105-.895 2-2 2H2c-1.105 0-2-.895-2-2V2C0 .895.895 0 2 0h36zM21.524 15v2.648C17.916 18.568 12.67 20.82 11 26c4.174-3.673 10.18-3.48 10.524-3.463v2.648L28 20.093 21.524 15z" transform="translate(-130 -369) translate(130 369)"/>
												</g>
											</g>
										</g>
									</svg>
								</button>
								<?php echo do_shortcode('[addtoany]'); ?>
							</div>
						</div>

					</div><!-- .meta -->

					
				</header><!-- .info -->

				<div class="entry container">
					<?php the_content(); ?>

					<div class="singleFooter">
						<div class="tags">
							<h6>Tags</h6>
							<?php
								$posttags = get_the_tags();
								if ($posttags) {
									foreach($posttags as $tag) {
										?>
										<a href="<?php echo get_tag_link($tag->term_id); ?>" class="bt-category"><?php echo $tag->name; ?></a>
										<?php
									}
								}
							?>
						</div>
						<div class="share">
							<h6>Share</h6>
							<?php echo do_shortcode('[addtoany]'); ?>
						</div><!-- .share -->
					</div>

					<!-- <div class="addhome adds addhome2">
						<div class="contentAdd" style="background: #000;"></div>
					</div> -->
					<div id="ad-internal-cat-pagination" >
						<?php echo do_shortcode( '[the_ad id="29732"]' ); ?>
					</div>
				</div><!-- .entry -->

				

				<div class="comments">
					<div class="container">
						<h3>Comments</h3>
						<?php
							// If comments are open or we have at least one comment, load up the comment template.
							if ( comments_open() || get_comments_number() ) {
								comments_template();
							}
						?>
					</div>
					
					
					<?php /*Caso seja do facebook: <div class="fb-comments" data-href="<?php the_permalink(); ?>" data-width="100%" data-numposts="5"></div>*/ ?>
				</div><!-- .comments -->
			</article><!-- .post -->

			<?php
				$args = array(
					'post_type' => 'post',
					'cat' => $category[0]->term_id,
					'post__not_in' => array($postID),
					'post_status' => 'publish',
					'posts_per_page' => 6
				);
				// The Query
				$the_query = new WP_Query( $args );
				
				// The Loop
				if ( $the_query->have_posts() ):
			?>
			<section class="nextPosts">
				<div class="container">
					<header class="headerSection"><h3 class="sectiontitle">What To Read Next</h3></header>
					<?php	
						while ( $the_query->have_posts() ) {
							$the_query->the_post();
					?>
						<?php include 'components/linkarticle-medium2.php' ?>
						
					<?php	} ?>
				</div>
			</section>
			<?php 
				endif;
				/* Restore original Post Data */
				wp_reset_postdata();
			?>
					
			<!-- <div class="addhome adds addhome1">
				<div class="contentAdd" style="background: #EF1366;"></div>
			</div> -->
		<?php endwhile; endif; ?>
		<div id="ad-internal-cat-bottompage" >
			<?php echo do_shortcode( '[the_ad id="29733"]' ); ?>
		</div>
	</div><!-- .content.inner.single -->

<?php get_footer(); ?>