Методы вывода терминов таксономии.
Список терминов таксономии с записями
В любом месте сайта мы можем вывести список терминов таксономии с записями. Для этого я сделал отдельный term-list.php.
Вызываем term-list.php
<?php get_template_part( 'term-list' ); ?>
Содержимое term-list.php
Название таксономии (выделено) меняем на нужное нам.
Также настраиваем необходимые типы записей.
Изучить тип записей any
<div class="podcat"> <?php $terms = get_terms('label','hide_empty=false'); ?> <?php if($terms) : ?> <?php foreach($terms as $term) : ?> <div class="block-podcategory"> <a href="<?php echo get_tag_link($term->term_id);?>"> <?php if($imgcat1=get_field("mini-thumb",$term)) : ?> <img class="cat-image" src="<?=$imgcat1['sizes']['square']?>"> <?php else: ?> <img class="cat-image" src="<?php bloginfo('template_url'); ?>/images/img-default-square.jpg"> <?php endif; ?> </a> <h3 class="title-2"><a href="<?php echo get_tag_link($term->term_id);?>"><i class="fa fa-tag"></i><?php echo $term->name;?></a></h3> <p class="count"><?php if ($term->count > 0) : ?><?php echo $term->count; ?><?php else: ?>0<?php endif; ?></p> <div class="descript-2"><p><?php if($term->description) : ?><?php echo $term->description; ?><?php else: ?>Описание термина таксономии<?php endif; ?></p></div> <ul> <?php global $post; $args = array( 'post_type' => array( 'post', 'page', 'track' ), 'tax_query' => array( array( 'taxonomy' => 'label', 'field' => 'term_id', 'terms' => $term->term_id ) ) ); $myposts = get_posts( $args ); foreach( $myposts as $post ) : setup_postdata($post); ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php endforeach; ?> <?php wp_reset_postdata() ?> </ul> </div> <?php endforeach; ?> <?php endif; ?> </div>
В данном функционале также реализована миниатюра термина таксономии, средствами произвольных полей
Простой вывод терминов таксономии
<?php global $post; $args = array( 'posts_per_page' => 10, 'post_type' => array( 'post', 'page', 'track' ), 'tax_query' => array( array( 'taxonomy' => 'category', 'include_children' => false, 'field' => 'term_id', 'terms' => 39 ) ) ); $myposts = get_posts( $args ); ?> <ul> <?php foreach( $myposts as $post ) : setup_postdata($post); ?> <li><a href="#" id="<?php the_ID(); ?>" class="ajax-post"><?php the_title(); ?></a></li> <?php endforeach; ?> </ul>[site-socialshare]