<?php get_header(); ?>
<?php

$field = get_field("term_thumbnail", get_term(get_queried_object_id()));

?>
    <div class="row clearfix d-block">
        <?php get_template_part( 'content-menu-item-header' ); ?>
        <div class="col-12 col-xl-9 float-left">
            <?php if($field > 0): ?>
                <div class="newstag">
                    <img class="newstag__img" src="<?php echo wp_get_attachment_image_url($field, (wp_is_mobile() ? "thumbnail" : "large")); ?>" loading="lazy" />
                    <div class="newstag__body">
                        <div class="newstag__body__title d-flex flex-row align-items-md-baseline">
                            <img src="<?= get_template_directory_uri() ?>/assets/img/subtract.svg" />
                            <h1><?php echo ucfirst(get_term(get_queried_object_id())->name); ?></h1>
                        </div>
                        <div class="newstag__body__text d-none d-md-block">
                            <?php echo (get_term(get_queried_object_id())->description); ?>
                        </div>
                    </div>
                </div>
                <div class="newstag__body__text d-md-none mb-4">
                    <?php echo (get_term(get_queried_object_id())->description); ?>
                </div>
            <?php else: ?>
                <?php $image = get_option('z_taxonomy_image'.get_queried_object_id()); ?>
                <?php if ($image != ''): ?>
                    <div class="newstag">
                        <img loading="lazy" class="newstag__img w-100" src="<?php echo $image; ?>" />
                        <div class="newstag__body">
                            <h1 class="newstag__body__title">
                                <?php echo ucfirst(get_term(get_queried_object_id())->name); ?>
                                <svg width="35" height="35" class="align-baseline svg-icon">
                                    <use xlink:href="/wp-content/themes/profile/assets/img/sprites-svg/dist/sprite.svg#tag-white"></use>
                                </svg>
                            </h1>
                            <div class="newstag__body__text">
                                <?php echo (get_term(get_queried_object_id())->description); ?>
                            </div>
                        </div>
                    </div>
                <?php else: ?>
                    <div class="onenews mb-0">
                        <h1 class="onenews__title">
                            <svg class="align-baseline svg-icon" width="36" height="37"><use xlink:href="/wp-content/themes/profile/assets/img/sprites-svg/dist/sprite.svg#tag"></use></svg>
                            <?php echo ucfirst(get_term(get_queried_object_id())->name); ?>
                        </h1>
                    </div>
                    <?php if (get_term(get_queried_object_id())->description != '') : ?>
                        <div class="pt-4 pb-4 post-tag-description">
                            <?php echo wpautop(get_term(get_queried_object_id())->description); ?>
                            <div class="clearfix"></div>
                        </div>
                    <?php endif; ?>
                <?php endif; ?>
            <?php endif; ?>
            <div class="newslist">
                <div class="newslist__result">
                    <?php if(get_queried_object_id() == 104756): ?>
                        <style>
                            .align-baseline.svg-icon {
                                display:none;
                            }
                        </style>
                    <?php endif; ?>
                    <?php if ( have_posts() ) : ?>
                        <?php
                        while ( have_posts() ) : $postNum++;
                            ad_inlist_mobile($postNum);
                            the_post();
                            get_template_part( 'content', 'post_tag' );
                        endwhile;
                        echo do_shortcode('[ajax_load_more cache="true" cache_id="'.wp_is_mobile().crc32('archive-post_tag').get_queried_object_id().get_last_id().'" id="tag_request" scroll_distance="50" button_label="Загрузить еще" container_type="div" post_type="profile_article,anew" offset="'.(get_option('posts_per_page')).'" posts_per_page="10" tag__and="'.get_queried_object_id().'"]');
                        ?>
                        <div class="hide-if-js">
                            <?php
                            the_posts_pagination(
                                [
                                    'end_size'     => 3,
                                    'mid_size'     => 3,
                                    'prev_next'    => 0,
                                ]
                            );
                            ?>
                        </div>
                    <?php
                    else :
                        get_template_part( 'content', 'none' );
                    endif;
                    ?>
                </div>
            </div>
        </div>
        <div class="col-12 col-md-4 col-xl-3 float-right">
            <div class="right-side">
                <?php dynamic_sidebar('right_sidebar'); ?></div>
                <div class="js-stickybit">
                    <?php get_template_part( 'content', 'ad' ); ?>
                </div>
            </div>
        </div>
    </div>
<?php get_footer(); ?>