西暦表示を和暦表示に変更

※自分に向けての忘備録です。

参考にしたサイト(コード引用元)

本家のフォーラムには神様がいらっしゃる・・・

設置したもの

functions.phpに以下記述

function jp_wareki( $datenum ) {
	$y = substr( $datenum, 0, 4 );
	$m = substr( $datenum, 4, 2 );
	$d = substr( $datenum, 6, 2 );
	if ( checkdate($m, $d, $y) ) {
		if ( $datenum >= 19890108 ) {
			$wname = "平成";
			$y -= 1988;
		} elseif ( $datenum >= 19261225 ) {
			$wname = "昭和";
			$y -= 1925;
		} elseif ( $datenum >= 19120730 ) {
			$wname = "大正";
			$y -= 1911;
		} elseif ( $datenum >= 18680125 ) {
			$wname = "明治";
			$y -= 1867;
		}
		$datenum = $wname.(string)$y;
	} else {
		$datenum = "日付が正しくありません。";
	}
return $datenum;
}

テンプレートに以下記述

<?php $wareki = the_date('Ymd', '', '', false);
echo jp_wareki($wareki); ?>
年度 記事一覧

これで、2015年と表示されるところが平成27年になります。
前の記事の「期間指定できるやつ」を一緒に合わせれば年度表示も可能ですね。
ありがとうございますm(_ _)m


Comments

“西暦表示を和暦表示に変更” への2件のフィードバック

  1. nike air jordan pour bebeのアバター
    nike air jordan pour bebe

    I’m truly enjoying the design and layout of your blog. It’s a very easy on the eyes which makes it much more enjoyable for me to come here and visit more often. Did you hire out a developer to create your theme? Exceptional work!
    nike air jordan pour bebe

    http://www.aerialprocap.com/aerial.asp?key=nike-air-jordan-pour-bebe
    1. えび子のアバター
      えび子

      Thank you for praise.
      I am building this site myself.
      Please come again.

コメントを残す