WordPressで新着記事の一覧を正常に表示したい
WordPressで自作のテーマで自分では解決できない問題が発生しています。
新着記事の一覧が正常に表示されない
jquery.autopagerで新着記事を「もっと見る」形式で表示させていますが。ページネーションでいういわゆる2ページ目以降の記事が1ページ目と同じ記事が表示され1ページ目の無限ループが生じています。 サイトURLは https://www.journase.waows.com/新着記事/ です。 なお、scriptの部分をdiv要素で囲っているのはscriptが正常に動作しない場合の対策です。 また、ほかのカテゴリー別の記事一覧(index.php)は正常に表示されています。
ソースコード
php
1 <?php query_posts('posts_per_page=10'); ?> 2 <?php if(have_posts()): while(have_posts()): the_post(); ?> 3 <div class="card mb-3"> 4 <div class="card-contents"> 5 <div class="row"> 6 <div class="col-lg-3"> 7 <?php if ( has_post_thumbnail($post_object->ID)): ?> 8 <?php 9 $thumbnail_id = get_post_thumbnail_id($post_object->ID); 10 $image = wp_get_attachment_image_src( $thumbnail_id, 'medium' ); 11 $src = $image[0]; 12 $width = $image[1]; 13 $height = $image[2]; 14 echo '<img class="card-img-top" src="'.$src.'" width="'.$width.'" height="'.$height.'" />'; 15 ?> 16 <?php endif; ?> 17 </div> 18 <div class="col-lg-9 ml-3 ml-lg-0 mr-3 mr-lg-0 my-3"> 19 <p class="font-weight-light d-inline-block mb-2 text-primary"> 20 <i class="fa fa-tag"></i> 21 <?php $cat = get_the_category(); ?> 22 <?php $cat = $cat[0]; ?> 23 <?php echo get_cat_name($cat->term_id); ?> 24 </p> 25 <h4 class="card-title"> 26 <strong> 27 <?php echo mb_strimwidth(get_the_title(), 0, 70, "…", "UTF-8"); ?> 28 </strong> 29 </h4> 30 <p class="card-text text-muted"> 31 <i class="fa fa-clock-o"></i> 32 <?php the_time( 'Y/m/d H:i' ); ?> 33 </p> 34 35 <a href="<?php the_permalink(); ?>" class="btn btn-outline-secondary">記事を読む</a> 36 </div> 37 </div> 38 </div> 39 </div> 40 <?php endwhile; endif; ?> 41 <?php if ( $wp_query->found_posts >10 ): ?> 42 <div id="next" class="mt-4"> 43 <a href="<?php echo next_posts(0, false); ?>"> 44 <button type="button" class="btn btn-outline-secondary">もっと見る</button> 45 </a> 46 <img id="loading" src="<?php echo get_template_directory_uri() ?>/jquery.autopager-1.0.0/ajax-loader.gif" width="31" height="31"> 47 </div> 48 <?php endif; ?> 49 <div> 50 <script> 51 var maxpage = <?php echo $wp_query->max_num_pages; ?>; 52 53 $('#loading').css('display', 'none'); 54 $.autopager({ 55 content: '.card', 56 link: '#next a', 57 autoLoad: false, 58 59 start: function(current, next) { 60 $('#loading').css('display', 'block'); 61 $('#next a').css('display', 'none'); 62 }, 63 64 load: function(current, next) { 65 $('#loading').css('display', 'none'); 66 $('#next a').css('display', 'block'); 67 if (current.page >= maxpage) { 68 $('#next a').hide(); 69 } 70 } 71 }); 72 73 $('#next a').click(function() { 74 $.autopager('load'); 75 return false; 76 }); 77 </script> 78 </div>
最後に
<?php query_posts('posts_per_page=10'); ?>の部分が無限ループを引き起こしていると考えていますが正しい表示方法がわかりません。解決策をよろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/02/17 12:26