今回は、検索結果表示用のテンプレートファイルsearch.phpを作成します。
なお、WordPressのテンプレートファイル、テンプレートファイル階層、命名ルールについては下記を参照ください。
テンプレート階層 – WordPress Codex 日本語版
●テンプレートファイルsearch.phpを作成
Twenty_Fourteenからsearch.phpコピーし、下記のように修正します。
<?php get_header(); ?>
<div class="col-xs-12 col-sm-9">
<?php
if ( have_posts() ) : ?>
<h1 class="page-title">
<?php printf( __( 'Search Results for: %s', 'twentyfourteen' ), get_search_query() ); ?>
</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を使って自作テーマ作成」の目次へ