WordPressテーマの日付表示を直す方法
WordPress.org のテーマディレクトリとかから海外の人が作ったテーマを落としてインスコすると、だいたい日付の書式がおかしかったりします。
このブログもテーマ変えてから日付が変だったので直し方を調べてみました。
日付書式の指定
まず日付の書式の指定方法ですが、the_time() という WordPress の関数の引数で指定できます。
以下はご覧のさくらたんどっとびーずのテーマのブログ記事タイトルの下の部分ですが、引数無しで the_time() を呼び出しているので 時:分
しか表示されません。
<?php the_category(',') ?>
—
<?php the_tags(__('Tags: '), ', ', ' — '); ?>
<?php the_author() ?>
@
<?php the_time() ?>
<?php edit_post_link(__('Edit This')); ?>
</div>
年月日 時分
にしたかったので、the_time() の引数を以下のように変更しました。
‘Y/m/d G:i’ が 年/月/日 時:分
の日付書式です。有効な日付書式は PHP の date 関数の仕様に従いますので詳しくはリンク先のマニュアル見てください。
日付書式を __() で括っているのは国際化対応のためです。WordPress は gettext を使ってメッセージを国際化しています。引数に対応する日本語書式が存在すれば使用されます。国際化等を気にせず独自書式に変えたい場合は __() を入れずに日付書式を指定してください。
‘Y/m/d G:i’ の場合、対応する日本語書式が存在しないのでそのまま表示されてしまいますが、’Y/m/d g:i:s A’ に変更すると日本語化された書式 ‘Y年n月j日 g:i:s a’ が使用されます。
どの書式が日本語化済みかは、wp-content/languages/ja.po ファイルで確認できます。WordPress 3.0.5 日本語版では以下のようになっていました。
日付書式 | 日本語書式 |
---|---|
Y/m/d g:i:s A | Y年n月j日 g:i:s a |
Y/m/d | Y年n月j日 |
Y/m/d \\a\\t g:i A | Y年n月j日 g:i a |
Y/m/d \\a\\t g:ia | Y年n月j日 g:i a |
F j, Y | Y年n月j日 |
g:i a | g:i A |
F j, Y g:i a | Y年n月j日 g:i A |
M j, Y @ G:i | Y年n月j日 @ G:i |
どのファイルを直す必要があるか調べる
書式指定方法も分かったので実際にテーマのファイルいじくっていくことにします。
とりあえずどのファイルを直さないといけないか把握する必要がありますが、WordPress の管理パネルのサイドバーの[外観]→[編集]からテーマのファイルを開いて目視でチェックは面倒くさいので grep で探すことにしました。
テーマのファイルはブログをインスコしたディレクトリの下に wp-content/themes/[テーマ名] ディレクトリにありますので、the_time で grep します。
$ grep the_time *
index.php: <div class="meta"><?php the_category(',') ?> — <?php the_tags(__('Tags: '), ', ', ' — '); ?> <?php the_author() ?> @ <?php the_time() ?> <?php edit_post_link(__('Edit This')); ?></div>
今使ってる Barecity テーマの場合は index.php だけ直せば良いようです。テーマによっては何個かファイル直さないといけないのでガンバってください。
んでわ。
[...] ・さくらたんどっとびーず [...]
[...] WordPressテーマの日付表示を直す方法 | さくらたんどっとびーず [...]
Thank you for every other magnificent article.
Where else may anybody get that kind of information in such
a perfect means of writing? I’ve a presentation subsequent week,
and I’m at the search for such info.
It’s great that you are getting thoughts from this
post as well as from our dialogue made at this time.
Great goods from you, man. I’ve understand your stuff previous to and you’re just too magnificent.
I actually like what you have acquired here, really like what you’re
stating and the way in which you say it. You make it enjoyable
and you still take care of to keep it sensible. I can not wait to read far more from
you. This is actually a terrific web site.
What a data of un-ambiguity and preserveness of valuable knowledge about unpredicted feelings.
Hello! I’m at work browsing your blog frrom my new iphone!
Just wanted to say I love reading hrough your blog and look forward to all your posts!
Keep up the superb work!
Wonderful blog! Do yoou have anny tips for aspiring
writers? I’m planning to start my own site soon but I’m a little lost on everything.
Would you propose starting with a free platform like WordPress or go for a paid option? There are so many options out there that I’m totally
overwhelmed .. Any recommendations? Thank you!
Hi sakuratan.biz Administrator, identical below: Link Text