
WordPressで固定ページを表示する時にデザインを決めるテンプレートファイルはpage.phpです。これをカスタマイズして一部のページだけデザインを変更したいなど、WordPressをカスタマイズしていると色々とやりたい事が増えてくると思います。
そこで今回は、ワードプレスの個別固定ページの作り方を紹介したいと思います。
まずは、固定ページの基本テンプレートpage.php
WordPressのテーマによって多少違いはあると思いますがTwenty Twelveの固定ページだと下記のような感じになります。
<?php
get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'page' ); ?>
<?php comments_template( '', true ); ?>
<?php endwhile; // end of the loop. ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
個別ページを作ってみよう!
ファイルをコピーしてファイル名をpage-test.phpにして編集してみましょう♪
そして、/*Template Name: 個別ページテスト*/ を追加して保存してください。
<?php
/*
* Template Name: 個別ページテスト
*/
get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'page' ); ?>
<?php comments_template( '', true ); ?>
<?php endwhile; // end of the loop. ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
上記のように保存出来たら
<?php
get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'page' ); ?>
<?php comments_template( '', true ); ?>
<?php endwhile; // end of the loop. ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
ファイルをコピーしてファイル名をpage-test.phpにして編集してみましょう♪
そして、
Hi, very nice website, cheers!
——————————————————
Need cheap and reliable hosting? Our shared plans start at $10 for an year and VPS plans for $6/Mo.
——————————————————
Check here: https://www.good-webhosting.com/