###実現したいこと
WordPressのカテゴリー別ページで、(archive.php)
記事1~10を大きめ枠で表示(A)、
その下に、記事11~20を小さめ枠で表示(B)し、Bにのみページャーを付けたいと考えています。
(投稿/月別/投稿者別アーカイブでも同じデザイン)
###発生している問題
A、B 2つのwhileループを設置した時点では、カテゴリ内の記事のみを表示しますが、
query_posts で posts_per_page や offset を指定すると
全記事を表示してしまいます。
どのようにすればうまくいくでしょうか。
query_posts は非推奨のため、WP_Query を使用したいと思いますが、
その場合の正しいループの仕方を教えていただけますでしょうか。
どうぞよろしくお願いいたします。
###該当のソースコード
<!-- A ここから--> <?php query_posts('posts_per_page=10'); if ( have_posts() ) : echo '<ul>'; while ( have_posts() ) : the_post(); get_template_part( 'content-archive', get_post_format() ); endwhile; echo '</ul>'; else : echo '<div>お探しの記事は見つかりませんでした</div>'; endif; ?> <!-- B ここから--> <?php query_posts('posts_per_page=10&offset=10'); if ( have_posts() ) : echo '<div class="article_list list_02 new matchHeight_list">'; echo '<ul>'; while ( have_posts() ) : the_post(); get_template_part( 'content-archive', get_post_format() ); endwhile; echo '</ul>'; if (function_exists('responsive_pagination')) { responsive_pagination($additional_loop->max_num_pages); }; echo '</div>'; endif; ?>
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/08/30 04:53