<!--[home/news]-->

<?php

    $news_date = "";

    $news_query = new WP_Query(
        [
            "post_type" => ["anew", "yellow"],
            "ignore_sticky_posts" => true,
            "posts_per_page" => 20,
            "order" => "DESC",
            "orderby" => "post_date"
        ]
    );

    $top = json_decode(
        get_option("ppp_options")
    );

    $ids = array_filter(
        array_map(
            function ($item) {
                return $item->id;
            }, $top
        )
    );


    $top_query = new WP_Query(
        [
            "post_type" => ["anew", "yellow"],
            "ignore_sticky_posts" => true,
            "post__in" => $ids,
            "posts_per_page" => -1,
            "order" => "DESC",
            "orderby" => "post_date"
        ]
    );


?>
<div class="col-12 col-md-4 col-xl-3 float-left">

    <div class="news cell d-flex">

        <ul class="nav nav-tabs news__tabs">

            <li class="nav-item">

                <a class="nav-link active" data-toggle="tab" data-target="#tab-news" href="/news/">

                    Новости

                </a>

                <a class="nav-link" href="/news/">

                    Новости

                </a>

            </li>

            <li class="nav-item">

                <a class="nav-link" data-toggle="tab" href="#tab-top10">

                    Топ-10

                </a>

            </li>

        </ul>

        <div class="tab-content news__tabs-content">

            <div class="tab-pane active container" id="tab-news">

                <div class="news__body">

                    <div class="scrollbar-macosx js-scrollbar">

                        <div class="news__body__inner" >

                            <?php if($news_query->have_posts()): ?>

                                <?php while ($news_query->have_posts()): ?>

                                    <?php $news_query->the_post(); ?>

                                    <?php if( $news_date !== get_the_date("Ymd") ): ?>

                                        <?php $news_date = get_the_date("Ymd"); ?>

                                        <?php if( $news_query->current_post !== 0 ) : ?>

                                            </ul>

                                        <?php endif; ?>

                                        <div class="news__date">

                                            <?= get_the_date("d.m.Y") ?>

                                        </div>

                                        <ul class="news__list">

                                    <?php endif; ?>

                                        <?php get_template_part("template-parts/home/news-item"); ?>

                                <?php endwhile; ?>

                            <?php endif; ?>

                        </div>

                    </div>

                </div>

            </div>

            <div class="tab-pane container" id="tab-top10">

                <div class="news__body">

                    <div class="scrollbar-macosx js-scrollbar">

                        <div class="news__body__inner">

                            <ul class="news__list__top">

                                <?php if($top_query->have_posts()): ?>

                                    <?php while ($top_query->have_posts()): ?>

                                        <?php $top_query->the_post(); ?>

                                        <?php get_template_part("template-parts/home/news-top-item"); ?>

                                    <?php endwhile; ?>

                                <?php endif; ?>

                            </ul>

                        </div>

                    </div>

                </div>

            </div>

        </div>

    </div>

</div>

<!--[/home/news]-->