Wordpressでブログカテゴリーの一覧を作っったのですが、
ページネーションがうまくうごきません。
▼ブログ一覧ページ(表示される)
wp/category/blog/campaign/
▼ブログ一覧ページ2ページ目(エラーで404になる)
wp/category/blog/campaign/page/2/
パーマリンクは
/%category%/%post_id%/
で設定しています。
おそらく、ブログ記事を参照して、そんなブログがないということになっているのかと思うのですが、
解決のアイディアが浮かばず、調べても全然わかりませんでした。
書いているコードは下記です。
function.php
1function pagination( $pages, $paged, $range = 2, $show_only = true ) { 2 3 $pages = ( int ) $pages; //float型で渡ってくるので明示的に int型 へ 4 $paged = $paged ?: 1; //get_query_var('paged')をそのまま投げても大丈夫なように 5 6 //表示テキスト 7 $text_first = "TOP"; 8 $text_before = ""; 9 $text_next = ""; 10 $text_last = "LAST"; 11 12 if ( $show_only && $pages === 1 ) { 13 // 1ページのみで表示設定が true の時 14 echo '<div class="pagination"><span class="current pager">1</span></div>'; 15 return; 16 } 17 18 if ( 1 !== $pages ) { 19 //2ページ以上の時 20 if ( $paged > 1 ) { 21 // 「最初へ」 の表示 22 echo '<a href="', get_pagenum_link(1) ,'" class="first">', $text_first ,'</a>'; 23 } 24 if ( $paged > 1 ) { 25 // 「前へ」 の表示 26 echo '<a href="', get_pagenum_link( $paged - 1 ) ,'" class="prev">', $text_before ,'</a>'; 27 } 28 for ( $i = 1; $i <= $pages; $i++ ) { 29 30 if ( $i <= $paged + $range && $i >= $paged - $range ) { 31 // $paged +- $range 以内であればページ番号を出力 32 if ( $paged === $i ) { 33 echo '<span class="current pager">', $i ,'</span>'; 34 } else { 35 echo '<a href="', get_pagenum_link( $i ) ,'" class="pager">', $i ,'</a>'; 36 } 37 } 38 39 } 40 if ( $paged < $pages ) { 41 // 「次へ」 の表示 42 echo '<a href="', get_pagenum_link( $paged + 1 ) ,'" class="next">', $text_next ,'</a>'; 43 } 44 if ( $paged < $pages ) { 45 // 「最後へ」 の表示 46 echo '<a href="', get_pagenum_link( $pages ) ,'" class="last">', $text_last ,'</a>'; 47 } 48 } 49} 50 51 52
category.php
1<?php 2 3 $paged = get_query_var('paged') ?: 1; 4 $args = array( 5 'paged' => $paged, 6 'posts_per_page' => 3 // 投稿件数の指定 7 ); 8 9 $the_query = new WP_Query($args); if($the_query->have_posts()): 10 ?> 11 <?php while ($the_query->have_posts()): $the_query->the_post(); ?> 12 13 <div class="box"> 14 <figure> 15 <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('archive_blog_img'); ?></a> 16 </figure> 17 <div class="textarea"> 18 <p class="date"><?php echo get_the_date(); ?></p> 19 <p class="b-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p> 20 <div class="b-content"> 21 <a href="<?php the_permalink(); ?>"><?php the_excerpt(); ?></a> 22 </div> 23 <div class="tags"> 24 <?php the_tags('<span class="tag">','</span><span class="tag">','</span>'); ?> 25 </div><!-- / tags--> 26 </div><!-- /textarea --> 27 </div><!-- /box --> 28 29 <?php endwhile; ?> 30 <?php else: ?> 31 <?php endif; ?> 32 33 </div><!-- /boxs --> 34 35 <div class="pagenation"> 36 <?php 37 if ( function_exists( 'pagination' ) ) : 38 pagination( $the_query->max_num_pages, $paged ); 39 endif; 40 ?> 41 42 43 <?php wp_reset_postdata(); ?>
あなたの回答
tips
プレビュー