カスタム投稿タイプでのサイドバーの表示について
-
カスタム投稿タイプのシングルページで、
サイドバーに表示する方法についてお教えください。シングルページの親のターム名を出し、
その子どもの記事一覧表示したいのですが、ターム親– 記事1
記事2
記事3このようにその記事の親タームとその子どもの記事一覧を表示させる方法をお教えください。
やってみた方法は、下記のやり方ですが、
全部のタームが表示されてしまい、
その記事の親だけを抜き出したいと思います。やった方法です。
<ul class="menu"> <?php $args = array( 'parent' => 0, 'hierarchical' => 0, 'orderby' => 'order', ); $taxonomy_name = 'tech-tax'; $taxonomys = get_terms($taxonomy_name,$args); if(!is_wp_error($taxonomys) && count($taxonomys)): foreach($taxonomys as $taxonomy): $url = get_term_link($taxonomy->slug, $taxonomy_name); $tax_posts = get_posts(array( 'post_type' => get_post_type(), 'posts_per_page' => -1, // 'tax_query' => array( array( 'taxonomy'=>'tech-tax', 'terms'=>array( $taxonomy->slug ), 'field'=>'slug', 'include_children'=>true, 'operator'=>'IN' ), 'relation' => 'AND' ) )); if($tax_posts): ?> <li id="<?php echo esc_html($taxonomy->slug); ?>" class="li-tech"><a href="<?php echo $url; ?>"><?php echo esc_html($taxonomy->name); ?></a></li> <ul class="ul-child"> <?php foreach($tax_posts as $tax_post): ?> <li class="li-child"><a href="<?php echo get_permalink($tax_post->ID); ?>"><?php echo get_the_title($tax_post->ID); ?></a></li> <?php endforeach; ?> </ul> <?php endif; endforeach; endif; ?> </ul>すみませんがよろしくお願いします。
3件の返信を表示中 - 1 - 3件目 (全3件中)
3件の返信を表示中 - 1 - 3件目 (全3件中)
トピック「カスタム投稿タイプでのサイドバーの表示について」には新たに返信することはできません。