お世話になります。
Wordpressにてテンプレートを作成中に行き詰まりましたので、
質問させていただきました。
現在、以下のような仕様でトップ(記事一覧)ページを作成しております。
・3個目の記事、6個目の記事、10個目の記事にそれぞれ指定カテゴリー及びタグの最新記事を挿入。
・他は最新記事から順に表示 (上記で指定したカテゴリーは出力させない)
offsetを使用し一旦以下のように作成しましたが、
query_postsにoffsetを入れるとページ送りができなくなるので、困っております。
php
1<main class="main"> 2 <div class="article__container"> 3 <?php query_posts('posts_per_page=10&paged='.$paged); ?> 4 <?php if (have_posts()) : while (have_posts()) : the_post(); ?> 5 6 <?php if ((loopCountNum())==2 ): ?> 7 <?php 8 $args = array( 9 'numberposts' => 2, 10 'category' => -3 11 ); 12 $my_posts = get_posts( $args ); 13 foreach ( $my_posts as $post ): setup_postdata( $post );?> 14 <article>内容</article> 15 <?php endforeach; ?> 16 17 <?php elseif((loopCountNum())==3 ): ?> 18 <?php 19 $args = array( 20 'numberposts' => 1, 21 'category' => 3, 22 'tax_query' => array( 23 array( 24 'taxonomy' => 'post_tag', 25 'field' => 'slug', 26 'terms' => 'keyword', 27 ), 28 ), 29 ); 30 $my_posts = get_posts( $args ); 31 foreach ( $my_posts as $post ): setup_postdata( $post );?> 32 <article>内容</article> 33 <?php endforeach; ?> 34 35 <?php elseif((loopCountNum())==5 ): ?> 36 <?php 37 $args = array('numberposts' => 2,'offset' => 2, 'category' => -3); 38 $my_posts = get_posts( $args ); 39 foreach ( $my_posts as $post ): setup_postdata( $post );?> 40 <article>内容</article> 41 <?php endforeach; ?> 42 43 <?php elseif((loopCountNum())==6 ): ?> 44 <?php 45 $args = array( 46 'numberposts' => 1, 47 'offset' => 0, 48 'category' => 3, 49 'tax_query' => array( 50 array( 51 'taxonomy' => 'post_tag', 52 'field' => 'slug', 53 'terms' => 'keyword2', 54 ), 55 ), 56 ); 57 $my_posts = get_posts( $args ); 58 foreach ( $my_posts as $post ): setup_postdata( $post );?> 59 <article> 60 </article> 61 <?php endforeach; ?> 62 63 /* 以下、 64 loopCountNum())==9, 65 loopCountNum())==10, 66 loopCountNum())==11 67 と続きます。*/ 68 69 70 <?php endwhile; ?> 71 <?php endif; ?> 72 73 </div> 74</main>
offsetを使用せずとも、上記仕様でどうにかページ送りに対応したページを作成できないでしょうか。
あなたの回答
tips
プレビュー