前回、投稿本文を表示するテンプレートファイルを作成しましたが、特定の投稿をクリックして単一の投稿のみ表示するとコメントフォームやコメントが表示されません。今回は、単一の投稿を表示するテンプレートファイルsingle.phpを作成します。
なお、WordPressのテンプレートファイル、テンプレートファイル階層、命名ルールについては下記を参照ください。
テンプレート階層 – WordPress Codex 日本語版
1)TwentyFourteenテーマのsingle.phpをコピーして流用
TwentyFourteenテーマのsingle.phpをコピーして流用します。レイアウト部分は後で自分用にスタイルリングするで削除し、下記のように記述します。
<?php get_header(); ?>
<div class="col-xs-12 col-sm-9">
<?php
while ( have_posts() ) : the_post();
get_template_part( 'content', get_post_format() );
// Previous/next post navigation.
twentyfourteen_post_nav();
if ( comments_open() || get_comments_number() ) {
comments_template();
}
endwhile;
?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
2)twentyfourteenのcomments.phpをコピー
comments_template();
の記述があるのでtwentyfourteenのcomments.phpをコピーしてそのまま流用します。
comments.php内の設定は後で別途行います。
なお、get_template_part( ‘content’, ‘page’ );
については、前回必要なテンプレートファイルをコピー済みです。
3)表示確認
単一の投稿を表示すると下にコメント投稿フォームが表示される事を確認します。
「ブートストラップ3を使って自作テーマ作成」の目次へ