<?php 
    $count = count(get_field('banners')); 
    $cont = 1;
?>
<?php if( have_rows('banners') ): ?>
    <section id="carouselHome">
        <div class="owl-carousel owl-carouselHome">
            <?php while( have_rows('banners') ): the_row(); 
                $IDpost = get_sub_field('post');
                $link = get_permalink($IDpost);
                $category = get_the_category($IDpost); 
                $terms = get_the_terms( $IDpost, 'countries' );
                $image = get_the_post_thumbnail_url($IDpost, 'full');
            ?>
                <article id="post-<?php echo $IDpost; ?>" class="item">
                    <a href="<?php echo $link; ?>" class="thumb bg-cat-<?php echo $category[0]->slug; ?>">
                        <?php if($image): ?><img class="owl-lazy" data-src="<?php echo $image; ?>" alt="<?php echo get_the_title($IDpost) ?>"><?php endif; ?>
                    </a>
                    <header class="container">
                        <div class="dados">
                            <a href="<?php echo get_category_link($category[0]->term_id); ?>" class="bt-category bt-cat-<?php echo $category[0]->slug; ?>-full"><?php echo $category[0]->name; ?></a> 
                            <span class="data"><?php echo $terms[0]->name; ?> | <?php echo get_the_time('M', $IDpost); ?> <?php echo get_the_time('j', $IDpost); ?>, <?php echo get_the_time('Y', $IDpost); ?></span> 
                        </div>
                        <h2 class="title"><a href="<?php echo $link; ?>"><?php echo get_the_title($IDpost) ?></a></h2>
                        <div class="bts">
                            <a href="<?php echo $link; ?>" class="btn bt-read">Read Now</a>
                        <?php if(get_field('video', $IDpost)): ?><a href="<?php echo $link; ?>" class="btn bt-watch">Watch Now</a><?php endif; ?>
                        </div>
                        <div class="cont">
                            <span class="actual"><?php echo $cont; ?></span> <span class="trace">/</span> <span class="total"><?php echo $count; ?></span>
                        </div>
                    </header>
                </article>
            <?php $cont++; endwhile; ?>
        </div>
        <div class="featured">
            <div class="container owl-carousel owl-featured">
                <?php while( have_rows('banners') ): the_row(); 
                    $IDpost = get_sub_field('post');
                    $link = get_permalink($IDpost);
                    $category = get_the_category($IDpost); 
                    $terms = get_the_terms( $IDpost, 'countries' );
                    $image = get_the_post_thumbnail_url($IDpost, 'thumb-post-supersmall');
                    $category_parent_id = $category[0]->category_parent;
                    if ( $category_parent_id != 0 ) {
                        $category_parent = get_term( $category_parent_id, 'category' );
                        $slugCat = $category_parent->slug;
                        $idCat = $category_parent->term_id;
                        $nameCat = $category_parent->name;
                    } else {
                        $slugCat = $category[0]->slug;
                        $idCat = $category[0]->term_id;
                        $nameCat = $category[0]->cat_name;
                    }
                    $catName = countText($nameCat, 9);

                ?>
                    <div class="component-linkarticle supersmall">
                        <a href="<?php echo $link; ?>" class="content-article bg-article-<?php echo $slugCat; ?>-hover">
                            <span class="component-thumb supersmall bg-cat-<?php echo $slugCat; ?>">
                                <?php if($image): ?><img src="<?php echo $image; ?>" alt="<?php echo get_the_title($IDpost) ?>"><?php endif; ?>
                            </span>
                            <header>
                                <div class="component-dados">
                                    <span class="category color-cat-<?php echo $slugCat; ?>"><?php echo $catName; ?> <span class="bg-cat-<?php echo $slugCat; ?>"></span></span>
                                    <span class="local"><?php echo $terms[0]->name; ?></span>
                                    <span>|</span>
                                    <span class="data"> <?php echo get_the_time('M', $IDpost); ?>  <?php echo get_the_time('j', $IDpost); ?> ,  <?php echo get_the_time('Y', $IDpost); ?></span>
                                </div>
                                <h3 class="h5"><?php echo countText(get_the_title($IDpost), 41) ?></h3>
                            </header>
                        </a>
                    </div>
                <?php endwhile; ?>
            </div>
        </div>
    </section>
<?php endif; ?><!-- Banner Home -->