Simplicityでのカスタム投稿タイプのアーカイブページ作成
archives-カスタム投稿名.phpを作成
カスタム投稿タイプのトップページ(記事一覧)
親テーマの list.php をコピーしてカスタム投稿タイプ用のファイル名に変更します。
ファイル名の末尾に任意の名前を追加
archive-party.php
中身も少々いじる。
パンくずリストをカスタム投稿タイプ用に breadcrumbs の後ろに『-party』を追加。
breadcrumbs-party
1行目
変更前
<?php //////////////////////////// //パンくずリスト //////////////////////////// if (is_category()) { get_template_part('breadcrumbs'); } ?>
変更後
<?php //////////////////////////// //パンくずリスト //////////////////////////// if (is_category()||is_archives) { get_template_part('breadcrumbs-party'); } ?>
アーカイブのタイトルをタグのタイトルに変更し、ターム(カテゴリ)の説明文を追加。
10行目くらい
変更前
<?php //////////////////////////// //アーカイブのタイトル //////////////////////////// if (!is_home() && !is_search()) { ?> <h1 id="archive-title"><?php echo get_archive_chapter_text(); ?></h1> <?php } ?>
変更後
<?php //////////////////////////// //タグのタイトル //////////////////////////// if (!is_home() && !is_search()) { ?> <h1 id="archive-title"><?php echo get_post_type_object(get_post_type())->label; ?><?php single_tag_title(); ?></h1> <?php } ?> <!-- カテゴリの説明文 --> <div class="category-description"><?php echo get_post_type_object(get_post_type())->description; ?></div>
ターム(カテゴリ)の説明文を追加。
36行目くらい
変更前
<?php //////////////////////////// //カテゴリ説明文の挿入 //////////////////////////// if (is_category() && //カテゴリページの時 !is_paged() && //カテゴリページのトップの時 category_description()) : //カテゴリの説明文が空でない時 ?> <!-- カテゴリの説明文 --> <div class="category-description"><?php echo category_description(); ?></div> <?php endif; ?>
このうち以下部分
<?php echo category_description(); ?>
ここを
<?php echo get_post_type_object(get_post_type())->description; ?>
に変更する。
変更後
<?php //////////////////////////// //カテゴリ説明文の挿入 //////////////////////////// if (is_category() && //カテゴリページの時 !is_paged() && //カテゴリページのトップの時 category_description()) : //カテゴリの説明文が空でない時 ?> <!-- カテゴリの説明文 --> <div class="category-description"><?php echo get_post_type_object(get_post_type())->description; ?></div> <div class="category-description"><?php echo category_description(); ?></div> <?php endif; ?>
ターム(タグ)の説明文を追加。
47行目くらい
変更前
<?php //////////////////////////// //タグ説明文の挿入 //////////////////////////// if (is_tag() && //タグページの時 !is_paged() && //タグページのトップの時 tag_description()) : //タグの説明文が空でない時 ?> <!-- カテゴリの説明文 --> <div class="category-description tag-description"><?php echo tag_description(); ?></div> <?php endif; ?>
このうち以下部分
<?php echo tag_description(); ?>
ここを
<?php echo get_post_type_object(get_post_type())->description; ?>
に変更する。
変更後
<?php //////////////////////////// //タグ説明文の挿入 //////////////////////////// if (is_archive() && //タグページの時 !is_paged() && //タグページのトップの時 tag_description()) : //タグの説明文が空でない時 ?> <!-- カテゴリの説明文 --> <div class="category-description tag-description"><?php echo get_post_type_object(get_post_type())->description; ?></div> <div class="category-description tag-description"><?php echo tag_description(); ?></div> <?php endif; ?>
一覧リストに-partyを加える
71行目くらいからの//一覧リストのスタイルから下にある
entry-body
entry-card
entry-card-large
の末尾に『-party』を追加
entry-body-party
entry-card-party
entry-card-large-party
変更前
//一覧リストのスタイル if ( is_list_style_bodies() ) {//一覧表示スタイルが本文表示 get_template_part('entry-body');//一覧表示スタイルが本文表示の場合 } else if ( is_list_style_large_cards() ){//大きなエントリーカードの場合 get_template_part_card('entry-card-large'); } else if ( is_list_style_large_card_just_for_first() ){//最初だけ大きなエントリーカードの場合 //最初だけ大きなものであとは普通のエントリーカード if ( is_home() && !is_paged() && $count == 1 ) { get_template_part_card('entry-card-large'); } else { get_template_part_card('entry-card'); } } else if ( is_list_style_body_just_for_first() ){//最初だけ本文表示の場合 //最初だけ本文表示であとは普通のエントリーカード if ( is_home() && !is_paged() && $count == 1 ) { get_template_part('entry-body'); } else { get_template_part_card('entry-card'); } } else {//エントリーカードか、大きなサムネイルカードの場合 //一覧表示スタイルがカードor大きなサムネイルカード表示の場合 get_template_part_card('entry-card'); }
変更後
//一覧リストのスタイル if ( is_list_style_bodies() ) {//一覧表示スタイルが本文表示 get_template_part('entry-body-party');//一覧表示スタイルが本文表示の場合 } else if ( is_list_style_large_cards() ){//大きなエントリーカードの場合 get_template_part_card('entry-card-large-party'); } else if ( is_list_style_large_card_just_for_first() ){//最初だけ大きなエントリーカードの場合 //最初だけ大きなものであとは普通のエントリーカード if ( is_home() && !is_paged() && $count == 1 ) { get_template_part_card('entry-card-large-party'); } else { get_template_part_card('entry-card-party'); } } else if ( is_list_style_body_just_for_first() ){//最初だけ本文表示の場合 //最初だけ本文表示であとは普通のエントリーカード if ( is_home() && !is_paged() && $count == 1 ) { get_template_part('entry-body-party'); } else { get_template_part_card('entry-card-party'); } } else {//エントリーカードか、大きなサムネイルカードの場合 //一覧表示スタイルがカードor大きなサムネイルカード表示の場合 get_template_part_card('entry-card-party'); }
そしてその下(95行目くらい~)は全部削除します。
Simplicityはfooter.php でサイドバーを読み込んでいるので、
カスタム投稿タイプ用のサイドバーを作成した場合は、カスタム投稿タイプ用のフッターが必要になります。
先ほど削除したところに、フッターを読み込ませます。
<?php get_footer('party'); ?>