今回は、アーカイブ表示用のテンプレートファイルarchive.phpを作成します。
なお、WordPressのテンプレートファイル、テンプレートファイル階層、命名ルールについては下記を参照ください。
テンプレート階層 – WordPress Codex 日本語版
●テンプレートファイルarchive.phpを作成
Twenty_Fourteenからarchive.phpコピーし、下記のように修正します。
<?php get_header(); ?>
<div class="col-xs-12 col-sm-9">
<?php
if ( have_posts() ) : ?>
<h1 class="page-title">
<?php
if ( is_day() ) :
printf( __( 'Daily Archives: %s', 'twentyfourteen' ), get_the_date() );
elseif ( is_month() ) :
printf( __( 'Monthly Archives: %s', 'twentyfourteen' ),
get_the_date( _x( 'F Y', 'monthly archives dateformat', 'twentyfourteen' ) ) );
elseif ( is_year() ) :
printf( __( 'Yearly Archives: %s', 'twentyfourteen' ),
get_the_date( _x( 'Y', 'yearly archives date format', 'twentyfourteen' ) ) );
else :
_e( 'Archives', 'twentyfourteen' );
endif;
?>
</h1>
<?php
while ( have_posts() ) : the_post();
get_template_part( 'content', get_post_format() );
endwhile;
twentyfourteen_paging_nav();
else :
get_template_part( 'content', 'none' );
endif;
?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
●動作確認
①右サイドバーに”アーカイブ”ウィジェット追加
管理画面の「外観」→「ウィジェット」で”コンテンツサイドバー”に”アーカイブ”を追加します。
②ブラウザで表示確認
右サイドバーの月別アーカイブが表示されるので、クリックして表示を確認します。
「ブートストラップ3を使って自作テーマ作成」の目次へ