投稿記事の一覧(アーカイブ)ページを作成したのですが、blog/page/2/や/3/が1ページ目と同じ画面になってしまいます。また、1ページに5記事表示したいのですが、'posts_per_page' => 5が効かず3記事の表示になります。
どなたか解決方法を教えてください。よろしくお願いします。
(archive.php):テンプレートにして固定ページでアーカイブページを作成
php
1 2<?php /* 3Template Name: ブログ 4*/ ?> 5 6<?php get_header(); ?> 7 8<div id="content02"> 9<div id="content"> 10 11<div class="wrap"> 12 13 <div id="main" <?php bzb_layout_main(); ?> role="main" itemprop="mainContentOfPage" itemscope="itemscope" itemtype="http://schema.org/Blog"> 14 <div class="main-inner"> 15 16 <div class="page-header"> 17 <h1 class="post-title" ><?php bzb_title(); ?></h1> 18 </div> 19 20 <div class="post-loop-wrap"> 21 22 23 24<?php 25 $paged = get_query_var('paged') ? get_query_var('paged') : 1 ; 26 $args = array( 27 'post-type' => 'post', 28 'posts_per_page' => 5, 29 'paged' => $paged 30 ); 31 $my_query = new WP_Query($args); 32?> 33<?php 34 if( $my_query -> have_posts() ) : 35 while($my_query -> have_posts()) : $my_query -> the_post(); 36?> 37 38 39 <article id="post-<?php echo the_ID(); ?>" <?php post_class(); ?> itemscope="itemscope" itemtype="http://schema.org/BlogPosting"> 40 41 <header class="post-header"> 42 <div class="cat-name"> 43 <span> 44 <?php 45 $category = get_the_category(); 46 echo $category[0]->cat_name; 47 ?> 48 </span> 49 <ul class="post-meta list-inline"> 50 <li class="date" itemprop="datePublished" datetime="<?php the_time('c');?>"><i class="fa fa-clock-o"></i> <?php the_time('Y.m.d');?></li> 51 </ul> 52 </div> 53 <h1 class="post-title" itemprop="headline"><?php the_title(); ?></h1> 54 <div class="post-sns"> 55 <?php bzb_social_buttons();?> 56 </div> 57 </header> 58 59 <section class="post-content" itemprop="text"> 60 <?php the_excerpt(); ?> 61 </section> 62 63 <footer class="post-footer"> 64 <a class="morelink" href="<?php the_permalink(); ?>" rel="nofollow">続きを読む ≫</a> 65 </footer> 66 </article> 67 68 69 70 <?php 71 endwhile; 72 else : 73 ?> 74 75 <article id="post-404"class="cotent-none post" itemscope="itemscope" itemtype="http://schema.org/BlogPosting"> 76 <section class="post-content" itemprop="text"> 77 <?php echo get_template_part('content', 'none'); ?> 78 </section> 79 </article> 80 <?php 81 endif; 82 ?> 83 84<?php if (function_exists("pagination")) { 85 pagination($wp_query->max_num_pages); 86} ?> 87 88 89<?php wp_reset_postdata(); wp_reset_query(); ?> 90 91 </div><!-- /post-loop-wrap --> 92 93 94 95 </div><!-- /main-inner --> 96 </div><!-- /main --> 97 98<?php get_sidebar(); ?> 99 100</div><!-- /wrap --> 101 102</div><!-- /content --> 103</div><!-- /content02 --> 104 105<?php get_footer(); ?> 106 107 108
追加質問
per_get_postsを使って固定ページに表示することができたのですが、
投稿記事の一覧ではなく、この固定ページのタイトル「ブログ一覧」の1つのみ表示されてしまいました。
この場合はどこを修正したら良いのでしょうか?
PHP
1 2/* functions.php */ 3 4function change_posts_per_page($query) { 5 6if ( is_admin() || ! $query->is_main_query() ){ 7 return; 8 } 9 10 if ( $query->is_archive() ) { 11 $query->set( 'posts_per_page', '5' ); 12 return; 13 } 14 15} 16add_action( 'pre_get_posts', 'change_posts_per_page' ); 17
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/17 15:54
2018/10/17 16:22 編集
2018/10/17 19:06