
原因を調べると、have_posts() を使って、while( have_posts() ) ループの中で複数記事を表示させるときに表示されないことがあるようです。
さらにループの中で、同じ日に複数の記事がある場合に、2つめ以降の記事の日付が表示されない事がわかりました。
the_date() は、
/wp-inclueds/general-template.php
で定義されていて、そのソースを見ると、
function the_date( $d = ”, $before = ”, $after = ”, $echo = true ) {
global $currentday, $previousday;
$the_date = ”;
if ( $currentday != $previousday ) {
$the_date .= $before;
$the_date .= get_the_date( $d );
$the_date .= $after;
$previousday = $currentday;
$the_date = apply_filters(‘the_date’, $the_date, $d, $before, $after);
if ( $echo )
echo $the_date;
else
return $the_date;
}
return null;
}
となっています。
ソース中には以下の if 文がありますので、当該記事($currentday)と1つ前の記事($previousday)の日付が違う場合のみ、日付を出力するようになっています。
if ( $currentday != $previousday )
ソースの中のコメントでも、
Will only output the date if the current post’s date is different from theprevious one output.
と、書いてありますから、1つ前の記事($previousday)と同日の場合には the_date() が日付を出力しないのは WordPress の仕様のようです。
同一日付の日付を表示する
っで、どうするのか?という話ですが、単純に the_date() じゃなくて the_time() を使えばちゃんと表示されるみたいです。
参考:WordPress(ワードプレス)でthe_dateタグは同日だと表示されない | LIG
参考:[WordPress]日付表示で同じ日付が連続して表示されない場合
なので、
<?php the_date(‘Y年m月d日’) ?>
の部分を、
<?php the_time(‘Y年m月d日’) ?>
としたら無事に表示されるようになりました。それにしても、何でこんな仕様なんだろう。
でわでわ。