【wordpress】トップページ以外のページの作成

基本的なページ構造は共通しているので、トップページを生成するhome.phpのソースを元に作成する。

category.php、date.php、single.php、page.php


◼︎category.php(カテゴリーページ)

<?php get_header(); ?>

<!-- コンテンツ -->
<div id="content">
<p class="title"><?php single_cat_title(); ?></p>

<?php if(have_posts()): while(have_posts()): 
the_post(); ?>
	<?php get_template_part('content'); ?>
<?php endwhile; endif; ?>

<?php get_template_part('pagenation'); ?>
</div>

<?php get_sidebar(); ?>

<?php get_footer(); ?>

RECENT POSTからカテゴリーの名前を取得するように変更するだけ。


◼︎date.php(月別ページ)

<p class="title"><?php single_month_title(); ?></p>
<?php echo ge_the_date('Y年n月'); ?>

とすると、「2016年2月」という形で年月を出力できる。



◼︎single.php(記事の個別ページ)

<div id="content">
<?php if(have_posts()): while(have_posts()): 
the_post(); ?>
	<?php get_template_part('content'); ?>

<p class="pagenation">
<span class="oldpage"><?php previous_post_link(); ?></span>
<span class="newpage"><?php next_post_link(); ?> </span>
</p>
<?php endwhile; endif; ?>
</div>

ループの中に前後の記事へのリンクが必要。

◼︎page.php(固定ページ)

<div id="content">
<?php if(have_posts()): while(have_posts()): 
the_post(); ?>
	<div class="post">
	<h2><?php the_title(); ?></h2>
	<?php the_content(); ?>
	</div>
<?php endwhile; endif; ?>
</div>