ページ内に同じ日付を繰り返し表示する場合
2008-02-12
WordPressで、同じページ内に、同じ日付を繰り返し表示したいとき、通常のthe_date();テンプレートタグでは、きちんと表示されないときがあります。
そのときは、get_the_time()関数で年月日データを取得し、表示する方法があります。
たとえば、2005年3月12日のように表示したいときは、次のように記述します。
<?php
$d_year = get_the_time('Y');
$d_month = get_the_time('n');
$d_day = get_the_time('j');
echo $d_year."年".$d_month."月".$d_day."日";
?>
また、月別アーカイブのページで、月別アーカイブのリンクを表示したいときは、次のように記述します。
<?php
$arc_year = get_the_time('Y');
$arc_month = get_the_time('m');
?>
<a href="<?php echo get_month_link('$arc_year','$arc_month');?>">
<?php the_time('Y年m月');?>
</a>
