カスタム投稿タイプ
book
カスタムタクソノミー
bookcat
親カテゴリースラッグ
sf
子カテゴリースラッグ
japan
usa
「http://WordPressのURL/bookcat/sf/japan/」にjapanカテゴリーだけの記事一覧も表示させたいのです。
テンプレートはtexonomy-bookcat.phpで表示したいと思っています。
http://q.hatena.ne.jp/1382440478で回答をいただきましたが、新規投稿すると上書きされ、最新の一投稿しか表示されない状態です。
よろしくお願いいたします。
取得する投稿件数の変更は次のパラメータで可能です。
「posts_per_page」に「-1」を指定しても、「nopaging」に「true」を指定してもどちらでも大丈夫です。
http://wpdocs.sourceforge.jp/%E3%83%86%E3%83%B3%E3%83%97%E3%83%AC%E3%83%BC%E3%83%88%E3%82%BF%E3%82%B0/query_posts#.E3.83.9A.E3.83.BC.E3.82.B8.E9.80.81.E3.82.8A.E5.BC.95.E6.95.B0
ページ送り引数
- showposts (整数) - number of post to show per page. Deprecated in favor of 'posts_per_page'.
- posts_per_page (整数) - number of post to show per page. Use 'posts_per_page'=>-1 to show all posts. Note if the query is in a feed, wordpress overwrites this parameter with the stored 'posts_per_rss' option. To reimpose the limit, try using the 'post_limits' filter.
- nopaging (ブーリアン) - 全ての投稿を表示するかページ送りを使うかを指定します。デフォルトは'false'でページ送りを使います。
- paged (整数) - number of page. Show the posts that would normally show up just on page X when using the "Older Entries" link.
...( 略 )
Show All Post
Display all posts in one page:query_posts( 'posts_per_page=-1' );Display all posts by disabling pagination:
query_posts( 'nopaging=true' );
「query_posts()」でメインクエリを変更しても可能ですが、次のように「pre_get_posts」でリクエスト前に変更する方法が推奨されています。
・「functions.php」
function taxonomy_bookcat_archive_request( $query ) { if ( $query->is_tax( 'bookcat' ) && $query->is_main_query() ) { // 以下の2つの内どちらか1つを使用してください。 // $query->set( 'posts_per_page', '-1' ); $query->set( 'nopaging', true ); } } add_action( 'pre_get_posts', 'taxonomy_bookcat_archive_request' );
希望通りできました!!
2013/11/06 20:35:52本当にありがとうございます。
本当に素晴らしい説明をありがとうございます!
またよろしくお願いいたします。