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


Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/tomisan/www/info/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/tomisan/www/info/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/tomisan/www/info/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/tomisan/www/info/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/tomisan/www/info/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/tomisan/www/info/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/tomisan/www/info/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/tomisan/www/info/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/tomisan/www/info/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/tomisan/www/info/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/tomisan/www/info/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/tomisan/www/info/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/tomisan/www/info/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/tomisan/www/info/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/tomisan/www/info/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/tomisan/www/info/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/tomisan/www/info/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match_all(): Compilation failed: invalid range in character class at offset 4 in /home/tomisan/www/info/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 700

Warning: Invalid argument supplied for foreach() in /home/tomisan/www/info/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 707

Warning: preg_match_all(): Compilation failed: invalid range in character class at offset 4 in /home/tomisan/www/info/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 700

Warning: Invalid argument supplied for foreach() in /home/tomisan/www/info/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 707

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; ?>

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

コメントは受け付けていません。