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

固定ページを作ります。

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

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

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

<?php wp_list_pages(); ?>

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

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

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

<?php if(is_month()) : ?>
            <div class="page-header">
                <h1><?php single_month_title(); ?></h1>
            </div>
            <!--//page-header -->
<?php endif; ?>

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

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

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

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

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

<?php if(is_month()) : ?>~<?php endif; ?>

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

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

<main id="main" role="main">
    <div class="container">
    <section>
<?php if(is_category()) : ?>
<?php
$cats = get_categories();
foreach ($cats as $cat) :
?>
            <div class="page-header">
                <h1><?php echo $cat->name; ?></h1><?php echo category_description($cat->term_id); ?>
            </div>
            <!--//page-header -->
<?php endforeach; ?>
<?php endif; ?>
        <div class="row">
            <div class="col-md-9">
                
                <?php if(have_posts()): while(have_posts()): the_post(); ?>
                <article>

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

<?php if(is_category()) : ?>~<?php endif; ?>

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

<?php if(is_home()): ?>
                
<?php endif; ?>

                <?php if(is_archive()): ?>
                <nav>
                    <ul class="pager">
                       <li class="previous"><?php next_posts_link('<i class="fa fa-angle-left"></i> Older'); ?></li>
                       <li class="next"><?php previous_posts_link('Newer <i class="fa fa-angle-right"></i>'); ?></li>
                    </ul>
                    <!--//pager -->
                </nav>
                <!--//nav -->
                <?php endif; ?>

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

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

<?php if(is_home() or is_archive()): ?>
                <nav>
                    <ul class="pager">
                       <li class="previous"><?php next_posts_link('<i class="fa fa-angle-left"></i> Older'); ?></li>
                       <li class="next"><?php previous_posts_link('Newer <i class="fa fa-angle-right"></i>'); ?></li>
                    </ul>
                    <!--//pager -->
                </nav>
                <!--//nav -->
<?php endif; ?>

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