オリジナルのtheme(テーマ)を作る14:固定ページを作る

固定ページを作ります。

固定ページは、左側の一覧にある「固定ページ」をクリック。
「新規追加」からタイトルと中身を記述して公開します。

ブログや日記のように記事を投稿してコメントが付いたりするページではなく、
サイトについて、お問い合わせ、会社概要、事業内容などを
固定ページで作る感じですね。
固定ページは、ウィジェットにも追加できます。

ウィジェットを使わずに固定ページの一覧を出力するには

  1. <?php wp_list_pages(); ?>

上記のテンプレートタグで固定ページの一覧を出力できます。

オリジナルのtheme(テーマ)を作る13:月別ページを作る

月別ページの年月を出力します。

  1. <?php if(is_month()) : ?>
  2. <div class="page-header">
  3. <h1><?php single_month_title(); ?></h1>
  4. </div>
  5. <!--//page-header -->
  6. <?php endif; ?>

<?php single_month_title(); ?>
この場合、表記が「○月2016」という形になります。

表記をなじみのある形にする。

  1. <?php if(is_month()) : ?>
  2. <div class="page-header">
  3. <h1><?php echo get_the_time('Y年m月'); ?></h1>
  4. </div>
  5. <!--//page-header -->
  6. <?php endif; ?>

<?php echo get_the_time('Y年m月'); ?>
これで「2016年○月」という形で出力されます。

月別のページだけに出力されるようにする。

  1. <?php if(is_month()) : ?><?php endif; ?>

オリジナルのtheme(テーマ)を作る12:カテゴリーページを作る

index.phpで生成されるカテゴリーページを作ります。
ページの内容は記事の一覧とほとんど変わらないのですが
カテゴリー名とカテゴリーの説明をページの上部に出力します。

  1. <main id="main" role="main">
  2. <div class="container">
  3. <section>
  4. <?php if(is_category()) : ?>
  5. <?php
  6. $cats = get_categories();
  7. foreach ($cats as $cat) :
  8. ?>
  9. <div class="page-header">
  10. <h1><?php echo $cat->name; ?></h1><?php echo category_description($cat->term_id); ?>
  11. </div>
  12. <!--//page-header -->
  13. <?php endforeach; ?>
  14. <?php endif; ?>
  15. <div class="row">
  16. <div class="col-md-9">
  17. <?php if(have_posts()): while(have_posts()): the_post(); ?>
  18. <article>

カテゴリーのページだけに出力されるように下記のタグで囲みます。

  1. <?php if(is_category()) : ?><?php endif; ?>

カテゴリーのページの下部に古い記事、新しい記事へのpagerを出力させます。

  1. <?php if(is_home()): ?>
  2. <?php endif; ?>
  3. <?php if(is_archive()): ?>
  4. <nav>
  5. <ul class="pager">
  6. <li class="previous"><?php next_posts_link('<i class="fa fa-angle-left"></i> Older'); ?></li>
  7. <li class="next"><?php previous_posts_link('Newer <i class="fa fa-angle-right"></i>'); ?></li>
  8. </ul>
  9. <!--//pager -->
  10. </nav>
  11. <!--//nav -->
  12. <?php endif; ?>

記事の一覧ページとほぼ同じ感じです。

アーカイブ系をひとつにまとめる

  1. <?php if(is_home() or is_archive()): ?>
  2. <nav>
  3. <ul class="pager">
  4. <li class="previous"><?php next_posts_link('<i class="fa fa-angle-left"></i> Older'); ?></li>
  5. <li class="next"><?php previous_posts_link('Newer <i class="fa fa-angle-right"></i>'); ?></li>
  6. </ul>
  7. <!--//pager -->
  8. </nav>
  9. <!--//nav -->
  10. <?php endif; ?>

ひとつにまとめて、すっきりしました!