WordPressのカスタム投稿のタクソノミーに設定しているタームごとの記事一覧を、タームのタブで切り替えて表示させたいです。
イメージ
表示させるテンプレートファイル:taxonomy-works_type.php
カスタム投稿名:works
カスタムタクソノミー名:works_type
現在のコード
taxonomy
1 <?php // get_terms を使ったターム一覧の表示 2 $taxonomy_terms = get_terms('works_type'); // タクソノミースラッグを指定 3 if(!empty($taxonomy_terms)&&!is_wp_error($taxonomy_terms)){ 4 echo '<nav class="category-wrapper">'; 5 echo '<ul class="works-category-list">'; 6 foreach($taxonomy_terms as $taxonomy_term): // foreach ループの開始 7 ?> 8 <li class="category-item"><a href="<?php echo get_term_link($taxonomy_term); ?>" class="works-category<?php if($taxonomy_term->slug === $term){ echo ' current'; } ?>"><?php echo $taxonomy_term->name; ?></a></li> 9 <?php 10 endforeach; // foreach ループの終了 11 echo '</ul>'; 12 echo '</nav>'; 13 } 14 ?> 15 <div class="works-wrapper"> 16 <section> 17 <?php query_posts($query_string . "&pst_type=jiseki&posts_per_page=2&paged='.$paged"); ?> 18 <?php if (have_posts()) : while (have_posts()) : the_post(); ?> 19 <div> 20 21 <?php 22 $terms = get_the_terms( get_the_ID(), 'works_type' ); 23 if ( !empty($terms) ) : if ( !is_wp_error($terms) ) : 24 ?> 25 26 <?php foreach( $terms as $term ) : ?> 27 <span class="icon01 <?php echo "$term->slug"; ?>"><?php echo $term->name; ?></span> 28 <?php endforeach; ?> 29 30 <?php endif; endif; ?> 31 32 <h2 class="h2Style03"><?php the_title(); ?></h2> 33 <p><?php the_content(); ?></p> 34 </div> 35 <?php endwhile; endif; ?> 36 </section> 37 </div>
上記コードで今のところ上部のタームで選んだタブ通りにタームごとの一覧が切り替え表示できているのですが、WordPress非推奨のquery_postsが使われているのが気がかりでいます。
こちらを、WP_Queryかget_postsに書き換えたいのですが、当方まだまだメインループやサブループについて詳しくなく、書き換え方法が全くわかりません。
こちら、どなたかWP_Queryかget_postsの記述に書き換えていただけませんでしょうか??
何卒よろしくお願いいたします。
あなたの回答
tips
プレビュー