投稿のアーカイブ(投稿一覧)を設定後、条件分岐を指定する方法
-
いつも大変お世話になっております。
投稿のアーカイブ(投稿一覧)を設定したいと思い、
下記のサイトの方法で投稿のアーカイブが表示されるようにしました。function.phpに以下を追加したら意図どおりアーカイブページが表示されるようになったのですが、
/** * 投稿のアーカイブページを設定 */ add_filter('register_post_type_args', function($args, $post_type) { if ('post' == $post_type) { global $wp_rewrite; $archive_slug = 'news'; $args['label'] = 'ニュース'; $args['has_archive'] = $archive_slug; $archive_slug = $wp_rewrite->root.$archive_slug; $feeds = '(' . trim( implode('|', $wp_rewrite->feeds) ) . ')'; add_rewrite_rule("{$archive_slug}/?$", "index.php?post_type={$post_type}", 'top'); add_rewrite_rule("{$archive_slug}/feed/{$feeds}/?$", "index.php?post_type={$post_type}".'&feed=$matches[1]', 'top'); add_rewrite_rule("{$archive_slug}/{$feeds}/?$", "index.php?post_type={$post_type}".'&feed=$matches[1]', 'top'); add_rewrite_rule("{$archive_slug}/{$wp_rewrite->pagination_base}/([0-9]{1,})/?$", "index.php?post_type={$post_type}".'&paged=$matches[1]', 'top'); } return $args; }, 10, 2);
【参考サイト】
https://qiita.com/ki6ool/items/888385014c810c9d6becこの投稿のアーカイブページのみに表示される条件分岐、
もしくは archive-post.phpのような個別のテンプレートを指定するには
どのようにすればよいかご教授いただけないでしょうか。
お手数をおかけしますが
何卒よろしくおねがいします。
- トピック「投稿のアーカイブ(投稿一覧)を設定後、条件分岐を指定する方法」には新たに返信することはできません。