カテゴリーページの作成
続いてカテゴリーページの作成を行いましょう。
category.php
<?php 
get_header(); 
get_template_part('templates/main_contents', 'category');
get_footer();
main_contents部分がcategory専用になっている以外は特に変わったところはありません。
main_contents.php
<main class="main_contents">
  <section class="content">
    <?php 
    get_template_part( 'templates/breadcrumb', 'category' );
    while(have_posts() === true){
      the_post(); 
      get_template_part('templates/content'); 
    }
    get_template_part('templates/pagination');
    ?>
  </section>
  <?php
    get_sidebar();
  ?>
</main>
こちらもパンくずリストがcategory用になったのみで、あとは変わったところはありません。
breadcrumb-category
<?php
//カテゴリオブジェクトを取得
$first_category = get_queried_object();;
?>
<span class="breadcrumb" >
    HOME > 
    <?php 
        // 末尾の ' > ' を切り取る。
        print mb_substr(get_category_parents($first_category->term_id, true, ' > '), 0, -3); 
    ?>
</span>
カテゴリーページ向けのパンくずリストは上記のようになります。 個別記事ページ向けのパンくずリストによく似ていますが、get_category_parentsで得られる親カテゴリーへのリンクが連結した文字列から、余計な末尾の区切り文字を削除しています。 (削除する文字数は、区切り文字に設定した文字数に応じて調整しましょう。)