<?php 
    // get the current taxonomy term
    $category = get_the_category(); 
    $color = get_field('color', $category[0]);
    $category_parent_id = $category[0]->category_parent;
	if ( $category_parent_id != 0 ) {
    	$category_parent = get_term( $category_parent_id, 'category' );
    	$color = get_field('color', $category_parent);
	}
    
    // vars
    

    $terms = get_the_terms( $post->ID, 'countries' );
?>
<article id="post-<?php the_ID(); ?>" class="principal">
    <a href="<?php the_permalink(); ?>" class="thumb bg-cat-<?php echo $category[0]->slug; ?>">
        <?php if(has_post_thumbnail()): ?>
            <?php the_post_thumbnail( 'thumb-post-featured' ); ?>
        <?php endif; ?>
    </a>
    <header>
        <div class="dados">
            <a href="<?php echo get_category_link($category[0]->term_id); ?>" class="bt-category" style="background-color: <?php echo $color; ?>;"><?php echo $category[0]->cat_name; ?></a> 
            <span class="data"><?php echo $terms[0]->name; ?> | <?php the_time('M'); ?> <?php the_time('j'); ?>, <?php the_time('Y'); ?></span> 
        </div>
        <h2 class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
        <div class="bts">
            <a href="<?php the_permalink(); ?>" class="btn bt-read">Read Now</a>
            <?php if(get_field('video')): ?><a href="<?php the_permalink(); ?>" class="btn bt-watch">Watch Now</a><?php endif; ?>
        </div>
    </header>
</article>
