実現したいこと
category.phpの記事一覧で
ページネーションを入れて表示制限をかけたいのですが、
2ページ目以降でエラーが出てしまいます。
archive.phpでは機能してるのですが、
category.phpだけエラーが出てしまうようです・・・。
もしご存知の方がいらっしゃいましたら、
改善策等ご教示いただけましたら幸いです。
よろしくお願い致します。
該当のソースコード
category.php
<section class="section"> <div class="inner"> <div class="switchGroup"> <?php $categories = get_categories(); foreach ($categories as $category){ echo '<div class="switchWrap"><a class="switch" href="' . get_category_link($category->term_id) . '">' . $category->name . '</a></div>'; } ?> </div> <ul class="list"> <?php // $category_slug = get_query_var("category_name"); $args = array( "post_type" => "news", "posts_per_page" => 3, // "category_name" => $category_slug, "paged" => $paged ); $the_query = new WP_Query($args); if($the_query -> have_posts()): while($the_query -> have_posts()): $the_query -> the_post(); ?> <li class="item"> <a class="anchor" href="<?php the_permalink(); ?>"> <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> <h3 class="title"><?php the_title(); ?></h3> <div class="textWrap"><?php echo wp_trim_words( get_the_content(), 72, "..."); ?></div> </a> </li> <?php endwhile; endif; wp_reset_postdata(); ?> </ul> <?php if(function_exists("the_pagination")) the_pagination(); ?> </div> </section>
functions.php
// ページネーション function the_pagination(){ global $the_query; $bignum = 999999999; if ($the_query->max_num_pages <= 1) { return; } echo paginate_links(array( 'base' => str_replace($bignum, '%#%', esc_url(get_pagenum_link($bignum))), 'format' => '', 'current' => max(1, get_query_var('paged')), 'total' => $the_query->max_num_pages, 'prev_text' => '', 'next_text' => '', 'type' => 'list', 'end_size' => 0, 'mid_size' => 1 )); wp_reset_postdata(); }
試したこと
- パーマリンクの設定を変更してみたのですが特に変化はありませんでした。(現在、「投稿名」に設定しています。また、カテゴリーベースは空白にしてます)
- プラグイン「FV Top Level Categories」「WP No Category Base (WPML)」を入れても変化ありませんでした。
補足情報(FW/ツールのバージョンなど)
php 7.4.21
wordpress 6.0
1ページに表示する最大投稿数(管理画面): 1
まだ回答がついていません
会員登録して回答してみよう