投稿一覧ページはarchive.phpで作成します。
アーカイブページのポイント
- single_cat_title()は現在のカテゴリー名を出力するテンプレートタグです。
- グローバルナビにカテゴリ名を登録するとそのカテゴリ一覧となって表示されます。
- the_except()はプラグイン「WP Multibyte Patch」を有効化することで、何も設定していなければ110文字までの抜粋文字が表示されます。
<section id="contents">
<header class="page-header">
<h1 class="page-title"><?php single_cat_title(); ?></h1>
</header>
<div class="posts">
<?php
if (have_posts()) :
while (have_posts()) :
the_post();
get_template_part('content-archive');
endwhile;
endif;
?>
</div>
</section><!-- #contents end -->
<article <?php post_class(); ?>>
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('large_thumbnail', array('alt' => the_title_attribute('echo=0'),
'title' => the_title_attribute('echo=0'))); ?>
</a>
<header class="entry-header">
<time pubdate="pubdate" datetime="<?php the_time('Y-m-d'); ?>" class="entry-date">
<?php the_time(get_option('date_format')); ?></time>
<h1 class="entry-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
</header>
<section class="entry-content">
<?php the_excerpt(); ?>
</section>
</article>
抜粋の長さ(文字数)を変更するにはfunctions.phpに次を記述します。
function new_excerpt_mblength($length) {
return 100;
}
add_filter('excerpt_mblength', 'new_excerpt_mblength');
抜粋の最後には[…]と表示されますが、これを変更したい場合は以下のコードをfunctions.phpに追加します。
function new_excerpt_more($more) {
return '...';
}
add_filter('excerpt_more', 'new_excerpt_more');
続きを読むためのリンクを表示させたい場合には以下のコードをfunctions.phpに追加します。
抜粋の終端に表示される、[…]を変更で使用したfunctions.phpの内容を以下に変更
function new_excerpt_more($post) {
return '<a href="'. get_permalink($post->ID) . '">' . '続きを読む' . '</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');
