Wordpressでアーカイブページのページ送りが表示できません。。
(404.phpに遷移します)
結構困っています。。助けてください。。
状況というか、分かることを列挙して説明いたしますと、
・Underscoreをカスタマイズ
・ページ数(1,2,3・・・10)は問題なく取得できているがリンク先が表示できない。
・プラグインFV Top Level Categoriesをインストール。
・パーマリンクは「/%category%/%postname%」。
・「http://example.com/column/category-slug/page/1/」と打ったら表示できるが2ページ目以降はダメ。
・テスト環境だと問題ないが、本番環境だと本症状になる。
php
1//archive.php 2 3 <div id="primary" class="content-area"> 4 <main id="main" class="site-main" role="main"> 5 6 <?php 7 if ( have_posts() ) : ?> 8 9 <?php 10 $paged = get_query_var('paged'); 11 // カテゴリーページの表示件数を変更するには、posts_per_pageの数字を変更 12 query_posts($query_string . '&posts_per_page=8&paged=' . $paged); 13 /* Start the Loop */ 14 while ( have_posts() ) : the_post(); 15 16 /* 17 * Include the Post-Format-specific template for the content. 18 * If you want to override this in a child theme, then include a file 19 * called content-___.php (where ___ is the Post Format name) and that will be used instead. 20 */ 21 get_template_part( 'template-parts/content', 'listunit' ); 22 23 endwhile; 24 25 pagination(); 26 27 else : 28 29 get_template_part( 'template-parts/content', 'none' ); 30 31 endif; 32 wp_reset_query(); ?> 33 34 </main><!-- #main --> 35 </div><!-- #primary -->
php
1//function.php 2 3/*-------------------------------------------*/ 4/* Pasing 5/*-------------------------------------------*/ 6function pagination($max_num_pages = '', $range = 1) { 7 $showitems = ($range * 2)+1; 8 9 global $paged; 10 if(empty($paged)) $paged = 1; 11 12 if($max_num_pages == '') { 13 global $wp_query; 14 // 最後のページ 15 $max_num_pages = $wp_query->max_num_pages; 16 if(!$max_num_pages) { 17 $max_num_pages = 1; 18 } 19 } 20 21 if(1 != $max_num_pages) { 22 echo '<div class="paging_wrap">'."\n"; 23 echo '<ol class="paging">'."\n"; 24 25 // Prevリンク 26 // 現在のページが2ページ目以降の場合 27 if ($paged > 1) echo '<li><a class="prev_link" href="'.get_pagenum_link($paged - 1).'">«</a></li>'."\n"; 28 29 // 今のページからレンジを引いて2以上ある場合 && 最大表示アイテム数より最第ページ数が大きい場合 30 // (レンジ数のすぐ次の場合は表示する) 31 // 1...345 32 if ( $paged-$range >= 2 && $max_num_pages > $showitems ) echo '<li><a href="'.get_pagenum_link(1).'">1</a></li>'."\n"; 33 // 今のページからレンジを引いて3以上ある場合 && 最大表示アイテム数より最第ページ数が大きい場合 34 if ( $paged-$range >= 3 && $max_num_pages > $showitems ) echo '<li><span class="txt_hellip">…</span></li>'."\n"; 35 36 // レンジより前に追加する数 37 $addPrevCount = $paged+$range-$max_num_pages; 38 // レンジより後に追加する数 39 $addNextCount = -($paged-1-$range); // 今のページ数を遡ってカウントするために-1 40 // アイテムループ 41 for ($i=1; $i <= $max_num_pages; $i++) { 42 // 表示するアイテム 43 if ($paged == $i) { 44 $pageItem = '<li><span class="current">'.$i.'</span></li>'."\n"; 45 } else { 46 $pageItem = '<li><a href="'.get_pagenum_link($i).'" class="inactive">'.$i.'</a></li>'."\n"; 47 } 48 49 // 今のページからレンジを引いた数~今のページからレンジを足した数まで || 最大ページ数が最大表示アイテム数以下の場合 50 if ( ( $paged-$range <= $i && $i<= $paged+$range ) || $max_num_pages <= $showitems ) { 51 echo $pageItem; 52 // 今のページからレンジを引くと負数になる場合 && 今のページ+レンジ+負数をレンジに加算した数まで 53 } else if ( $paged-1-$range < 0 && $paged+$range+$addNextCount >= $i ) { 54 echo $pageItem; 55 // 今のページからレンジを足すと 最後のページよりも大きくなる場合 && 今のページ+レンジ+負数をレンジに加算した数まで 56 } else if ( $paged+$range > $max_num_pages && $paged-$range-$addPrevCount <= $i ) { 57 echo $pageItem; 58 } 59 } 60 61 // 現在のページにレンジを足しても最後のページ数より2以上小さい時 && 最大表示アイテム数より最第ページ数が大きい場合 62 if ( $paged+$range <= $max_num_pages-2 && $max_num_pages > $showitems ) echo '<li><span class="txt_hellip">…</span></li>'."\n"; 63 if ( $paged+$range <= $max_num_pages-1 && $max_num_pages > $showitems ) echo '<li><a href="'.get_pagenum_link($max_num_pages).'">'.$max_num_pages.'</a></li>'."\n"; 64 // Nextリンク 65 if ($paged < $max_num_pages) echo '<li><a class="next_link" href="'.get_pagenum_link($paged + 1).'">»</a></li>'."\n"; 66 echo "</ol>\n"; 67 echo "</div>\n\n"; 68 } 69}
不足している情報があれば是非教えて下さい。
追記------------------------------------
single.php に記述している所属しているカテゴリーを表示するコードも原因不明で出力がされていない状況でした。
ご参考になればと思い追記しました。
ここはマルっとUnderscoreのコードを流用しています。
html
1<p class="entry-category"><?php cseo_template_entry_footer(); ?></p> 2↓ 3<p class="entry-category"></p>
php
1if ( ! function_exists( 'cseo_template_entry_footer' ) ) : 2/** 3 * Prints HTML with meta information for the categories, tags and comments. 4 */ 5function cseo_template_entry_footer() { 6 // Hide category and tag text for pages. 7 if ( 'post' === get_post_type() ) { 8 /* translators: used between list items, there is a space after the comma */ 9 $categories_list = get_the_category_list( esc_html__( ', ', 'cseo_template' ) ); 10 if ( $categories_list && cseo_template_categorized_blog() ) { 11 printf( '<span class="cat-links">' . esc_html__( '%1$s', 'cseo_template' ) . '</span>', $categories_list ); // WPCS: XSS OK. 12 } 13 14 /* translators: used between list items, there is a space after the comma */ 15 // $tags_list = get_the_tag_list( '', esc_html__( ', ', 'cseo_template' ) ); 16 // if ( $tags_list ) { 17 // printf( '<span class="tags-links">' . esc_html__( 'Tagged %1$s', 'cseo_template' ) . '</span>', $tags_list ); // WPCS: XSS OK. 18 // } 19 } 20 21 if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) { 22 echo '<span class="comments-link">'; 23 /* translators: %s: post title */ 24 comments_popup_link( sprintf( wp_kses( __( 'Leave a Comment<span class="screen-reader-text"> on %s</span>', 'cseo_template' ), array( 'span' => array( 'class' => array() ) ) ), get_the_title() ) ); 25 echo '</span>'; 26 } 27 28 edit_post_link( 29 sprintf( 30 /* translators: %s: Name of current post */ 31 esc_html__( 'Edit %s', 'cseo_template' ), 32 the_title( '<span class="screen-reader-text">"', '"</span>', false ) 33 ), 34 '<span class="edit-link">', 35 '</span>' 36 ); 37} 38endif; 39 40/** 41 * Returns true if a blog has more than 1 category. 42 * 43 * @return bool 44 */ 45function cseo_template_categorized_blog() { 46 if ( false === ( $all_the_cool_cats = get_transient( 'cseo_template_categories' ) ) ) { 47 // Create an array of all the categories that are attached to posts. 48 $all_the_cool_cats = get_categories( array( 49 'fields' => 'ids', 50 'hide_empty' => 1, 51 // We only need to know if there is more than one category. 52 'number' => 2, 53 ) ); 54 55 // Count the number of categories that are attached to the posts. 56 $all_the_cool_cats = count( $all_the_cool_cats ); 57 58 set_transient( 'cseo_template_categories', $all_the_cool_cats ); 59 } 60 61 if ( $all_the_cool_cats > 1 ) { 62 // This blog has more than 1 category so cseo_template_categorized_blog should return true. 63 return true; 64 } else { 65 // This blog has only 1 category so cseo_template_categorized_blog should return false. 66 return false; 67 } 68}
回答1件
あなたの回答
tips
プレビュー