やりたい事
カスタム投稿のアーカイブページの表示件数を10件にして、それ以上になったら2ページ目、3ページ目となるようにしたい
現状
function.php
php
1add_action( 'init', 'create_post_type' ); 2function create_post_type() { 3 register_post_type( 4 register_post_type( 5 'test', 6 array( 7 'labels' => array( 8 'name' => __( 'テスト' ), 9 'singular_name' => __( 'テスト投稿' )), 10 'public' => true, 11 'has_archive' => true, 12 'supports' => array( 13 'title', 'post-formats') 14 ) 15 ); 16}
archive-test.php
(試行段階なので、1ページの表示件数を1件にしています)
php
1<?php 2$args = array('post_type' => 'test' , 'posts_per_page' => 1); 3$wp_query = new WP_Query( $args ); 4?> 5<?php if(have_posts()): while(have_posts()): the_post(); ?> 6//出力命令 7<?php endwhile; endif; wp_reset_query(); ?>
function.phpに'has_archive' = trueを記述して
https://www.サイト名/test/
でアーカイブページを表示しています。
ページャーも設定しました。
困っていること
3件投稿したところ
一覧ページの表示は1件のみ、ページャーも表示され
https://www.サイト名/test/
https://www.サイト名/test/page/2/
https://www.サイト名/test/page/3/
となります。
しかし、全ページとも3つ目の投稿(最新の投稿)が表示されてしまいます。
他の投稿も表示するにはどうしたらよいでしょうか?
なるべくプラグインは使わずに設定したいと思っています。
function.phpに何か記述が必要でしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/08/02 03:35