カテゴリーページの優先順位は下記の通りなんだけど
category-slug.php -- 特定のカテゴリー用テンプレート
category-ID.php -- 特定のカテゴリー用テンプレート
category.php -- カテゴリーの汎用テンプレート
archive.php -- 汎用アーカイブテンプレート(タグ・日別アーカイブなどと共用)
index.php
(参考:WordPress Codex)
カテゴリーのデザインを変更したときに、そのカテゴリーの子カテゴリーまでデザインは引き継がれないんですよね。
これfunction.php内に記述するといいと聞いて…知らなかった…のでメモ
add_filter( 'category_template', 'my_category_template' ); function my_category_template( $template ) { $category = get_queried_object(); if ( $category->parent != 0 && ( $template == "" || strpos( $template, "category.php" ) !== false ) ) { $templates = array(); while ( $category->parent ) { $category = get_category( $category->parent ); if ( !isset( $category->slug ) ) break; $templates[] = "category-{$category->slug}.php"; $templates[] = "category-{$category->term_id}.php"; } $templates[] = "category.php"; $template = locate_template( $templates ); } return $template; }
ソース元は子カテゴリのアーカイブページを親カテゴリ用のテンプレートファイルで表示しよう
今後も使うことになるだろうからメモ。