実現したいこと
category.phpの記事一覧で
ページネーションを入れて表示制限をかけたいのですが、
2ページ目以降でエラーが出てしまいます。
archive.phpでは機能してるのですが、
category.phpだけエラーが出てしまうようです・・・。
もしご存知の方がいらっしゃいましたら、
改善策等ご教示いただけましたら幸いです。
よろしくお願い致します。
該当のソースコード
category.php
1 <section class="section"> 2 <div class="inner"> 3 <div class="switchGroup"> 4 <?php 5 $categories = get_categories(); 6 foreach ($categories as $category){ 7 echo '<div class="switchWrap"><a class="switch" href="' . get_category_link($category->term_id) . '">' . $category->name . '</a></div>'; 8 } 9 ?> 10 </div> 11 <ul class="list"> 12 <?php 13 // $category_slug = get_query_var("category_name"); 14 $args = array( 15 "post_type" => "news", 16 "posts_per_page" => 3, 17 // "category_name" => $category_slug, 18 "paged" => $paged 19 ); 20 $the_query = new WP_Query($args); 21 if($the_query -> have_posts()): 22 while($the_query -> have_posts()): 23 $the_query -> the_post(); 24 ?> 25 <li class="item"> 26 <a class="anchor" href="<?php the_permalink(); ?>"> 27 <div class="dateWrap"><span class="date"><?php the_time("Y.m.d"); ?></span><span class="category"><?php $cat = get_the_category(); $cat = $cat[0]; { echo $cat->cat_name; } ?></span></div> 28 <h3 class="title"><?php the_title(); ?></h3> 29 <div class="textWrap"><?php echo wp_trim_words( get_the_content(), 72, "..."); ?></div> 30 </a> 31 </li> 32 <?php 33 endwhile; 34 endif; 35 wp_reset_postdata(); 36 ?> 37 </ul> 38 <?php if(function_exists("the_pagination")) the_pagination(); ?> 39 </div> 40 </section>
functions.php
1// ページネーション 2function the_pagination(){ 3 global $the_query; 4 $bignum = 999999999; 5 if ($the_query->max_num_pages <= 1) { 6 return; 7 } 8 echo paginate_links(array( 9 'base' => str_replace($bignum, '%#%', esc_url(get_pagenum_link($bignum))), 10 'format' => '', 11 'current' => max(1, get_query_var('paged')), 12 'total' => $the_query->max_num_pages, 13 'prev_text' => '', 14 'next_text' => '', 15 'type' => 'list', 16 'end_size' => 0, 17 'mid_size' => 1 18 )); 19 wp_reset_postdata(); 20}
試したこと
- パーマリンクの設定を変更してみたのですが特に変化はありませんでした。(現在、「投稿名」に設定しています。また、カテゴリーベースは空白にしてます)
- プラグイン「FV Top Level Categories」「WP No Category Base (WPML)」を入れても変化ありませんでした。
補足情報(FW/ツールのバージョンなど)
php 7.4.21
wordpress 6.0
1ページに表示する最大投稿数(管理画面): 1
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/07/11 01:25