タイトルの通りです。記事を20件表示させたいのですが、10件しか表示できず悩んでいます。
最初に表示される20件はphpで描画し、残りの記事はAjaxで非同期で読み込む仕様にしたいです。
$counter = 0;
のフラグを設定しているのは1件目の記事は大きく表示するためです。
どうかよろしくお願いします。
コードは以下です。
php
1<?php if ( have_posts() ) : ?> 2 3<section> 4 5<?php 6 7 $args = array( 8 'category_name' => 'tech', 9 'posts_per_page' => 20 10 ); 11 12 $query = new WP_Query( $args ); 13 $counter = 0; 14 15 while ( $query->have_posts() ) { 16 $query->the_post(); 17 if ($counter == 0) { 18 get_template_part('template-parts/content', 'unit_first'); 19 20 echo '<div class="block__unit__more">'; 21 } 22 else { 23 get_template_part('template-parts/content', 'unit'); 24 } 25 $counter += 1; 26 } 27 wp_reset_postdata(); 28?> 29</div> 30</section> 31<section> 32<?php 33 echo do_shortcode('[ajax_load_more post_type="post" posts_per_page="10" max_pages="0" category="'. $category_slug .'"]'); 34?> 35</section> 36 37<?php else : ?> 38 39<section> 40 41<?php 42 get_template_part( 'template-parts/content', 'none' ); 43?> 44 45</section> 46 47<?php endif; ?>
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/07/05 10:40
2017/07/05 10:43
退会済みユーザー
2017/07/05 11:01
2017/07/05 11:08
退会済みユーザー
2017/07/05 11:16
2017/07/05 12:29
退会済みユーザー
2017/07/06 01:26