• 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細

このWikiはいつでも誰でも編集できます

投稿メタデータセクション

提供: WordPress Codex 日本語版
Post Meta Data Sectionから転送)
移動先: 案内検索

ページ名検討中: このページ名「投稿メタデータセクション」について改名が提案されています。ご意見をお寄せください。

このページ「投稿メタデータセクション」はテキストの変更節以降が未翻訳です。和訳や日本語情報を加筆してくださる協力者を求めています

投稿メタデータ は各投稿を見る人へ提供する「管理用」の情報です。ふつうは、投稿の作成者、作成日(または公開日)、作成者が投稿を分類したカテゴリーが含まれます。このレッスンでは、あなたが望む形でこれらの重要な情報を表示できるようにテーマのデザインを変更する方法をいくつか紹介します。

多くの場合、投稿メタデータは投稿のすぐあとに表示されます。他には投稿の上に表示するテーマや、投稿メタデータをサイドバーの上端や下端に表示するデザイン、なかにはフッターにその情報を表示するデザインもあります。基本的に、投稿メタデータは数多くのスタイルでいろいろな詳細を表示できます。

注意 このページの例では、すでに非推奨とされたテンプレートタグが一部に使われています。そのため最新の WordPress では例のとおりに表示されない場合があります。

デフォルトの WordPress テーマは、投稿メタデータの基本情報とタグをボックスに入れて投稿の後・コメントの前に表示します。そのコードを縮めると次のようになります:

<small>This entry was posted on 
<?php the_time('l, F jS, Y') ?> at 
<?php the_time() ?> and is filed 
under <?php the_category(', ') ?>. You 
can follow any responses to this entry 
through the <?php comments_rss_link('RSS 2.0'); ?> 
feed.</small>

出力は次のようになります:

This entry was posted on Monday, February 12, 2003 at 11:32 and is filed under WordPress Lessons, Things to Know. You can follow any responses to this entry though the RSS 2.0 feed.

ここでは 3 つのテンプレートタグを使って投稿メタデータを表示しています。ひとつは the_time() で、違う表示のために 2 回使われています。他の 2 つのタグは、カテゴリーおよび RSS フィードへのリンクをデータベースから取得しています。

the_time() テンプレートタグは、いろいろなパラメータを指定して、投稿の時刻と日付をデータベースから取得できます。最初の使い方はパラメータが l, F jS, Y で、投稿の日付を 曜日, 月, 日, 年 の形式で取得します。2 つめはパラメータを指定しないので、投稿が保存された時刻だけを返します。後ほど 時刻と日付の変更 セクションで練習しましょう。

the_category() テンプレートタグは投稿が属するカテゴリーを表示します。このテンプレートタグはテキスト、画像、画像の間のシンボルを変更できます。さらに、単語のところに画像を表示するプラグインを利用できるかもしれません。これらに多くの方法でスタイルがつけられます。この例では、カテゴリーコンマ区切り /en のリストで表示しています。

最後のタグは comments_rss_link() で、パラメーターに RSS 2.0 を指定してフィードのタイプを決めています。また フィードタグをカスタマイズ /en して、フィードとタイプのリンク情報の表示方法を変えたり、テキストの代わりにフィードアイコンを表示したりできます。

テキストの変更

Let's start to rearrange your post meta data with small steps. The first step is to change the text but not the tags. After all, this is your website and you want it to say things your way, right? This example makes the post meta data a little more conversational:

<small>I slaved away at the computer on <?php the_time('l, F jS, Y') ?> 
at the ridiculous time of <?php the_time() ?> when I could have 
been doing something much more productive.  I slapped this 
thing into the <?php the_category(' and ') ?> categories, just 
to make you think I have some organizational skills.  If you 
can really be bothered, you can keep track of what people 
have to say about my silly writings through the 
<?php comments_rss_link('RSS 2.0'); ?> feed, but I 
wouldn't bother.  No one else who reads this babble has 
anything worthwhile to say.</small>

This would result in:

I slaved away at the computer on Monday, February 12, 2003 at the ridiculous time of 11:32. when I could have been doing something much more productive. I slapped this thing into the WordPress Lessons and Things to Know. categories, just to make you think I have some organizational skills. If you can really be bothered, you can keep track of what people have to say about my silly writings through the RSS 2.0 feed, but I wouldn't bother. No one else who reads this babble has anything worthwhile to say.

Okay, there is a small change. Did you catch it?

The usage of the_category() template tag, the parameter that sets the separator between the list of categories /en where the post belongs, was changed from a comma (,) to the word "and". It makes more sense in this situation.

Now, you can also cut the chatter and make your post meta data short and sweet:

POSTED: <?php the_time('m/j/y g:i A') ?><br />
FILED AS: <?php the_category(', ') ?><br />
COMMENTS FEED: <?php comments_rss_link('RSS 2.0'); ?>

Here is a very short list of your post meta data:

POSTED: 05/12/04 9:35 AM

FILED AS: News, Answers

COMMENTS FEED: RSS 2.0

時刻と日付の変更

There are many ways to change the time and date within your post meta data to reflect a more appropriate use for your website or your cultural timekeeping methods. For example, in much of the world, the date is not month day, year but day month year. In the post meta data, you would change the template tag the_time() so the paramters would show "Monday, 21 February 2005":

<?php the_time('1, jS F Y') ?>

To add more interesting information to your post meta data there are several plugins available which generate the date the post was last modified. Two such plugins are Kaf Oseo's Post Updated and Nick Momrik's Last Modified. In the following example, using various ways of manipulating time with PHP tags, we'll add Nick Momrik's plugin to the mix, mdv_last_modified():

<div class="postmetadata">This post was written on what I 
think was a <?php the_time('l'); ?>, but I know it was 
the <?php the_time('jS'); ?> day in the month 
of <?php the_time('F'); ?> in the year of 
<?php the_time('Y'); ?>, though I messed around 
with this on the <?php mdv_last_modified('dS'); ?> day 
of <?php mdv_last_modified('F'); ?> in 
<?php mdv_last_modified('Y'); ?>, a not-so-busy 
<?php mdv_last_modified('l'); ?> when I had nothing 
better to do.</p></div>

Which would result in:

This post was written on what I think was a Tuesday, but I know it was the 15th day in the month of February in the year of 2004, though I messed around with this on the 10th day of August in 2004, a not-so-busy Thursday when I had nothing better to do.

テンプレートタグの追加

So far, you've covered only three of the many template tags you can add to your post meta data. You can add the the_title() to get the title of the post. If you want the author's name, you can add the_author() and even the author's email with the_author_email(). Want a link to all the posts written by a specific author? That can be arranged with the the_author_posts_link().

What if you want to include more basic information like the title of the website using bloginfo(), or navigation help like the previous_post() and next_post()? We're using the next and previous post template tags to list posts within the same category, available to users of WordPress 1.5.1.3+. These are just a few examples of the many possible uses of template tags in your post meta data

In the most simplest of usages, the post meta data could be listed as:

POST TITLE: <?php the_title(); ?><br />
AUTHOR: <?php the_author(); ?><br />
POSTED: <?php the_time('jS F Y') ?><br />
FILED AS: <?php the_category(', ') ?><br />
COMMENT FEED: <?php comments_rss_link('RSS 2.0'); ?><br />
PREVIOUS: <?php previous_post('%', '', 'yes', 'yes'); ?><br />
NEXT: <?php next_post('%', '', 'yes', 'yes'); ?>

And would look like this:

POST TITLE: WordPress Makes Me Smile

AUTHOR: Harriet Smith
POSTED: 20 April 2004
FILED AS: WordPress, News
COMMENT FEED: RSS 2.0
PREVIOUS: Things to Do With WordPress

NEXT: Why I Like WordPress

If you want this in your sidebar, and you want a more conversational style, then in your template file, sidebar.php, find a good spot to put the following:

<div class="postmetadata"><p>You are reading the article, 
<?php the_title(); ?>, on our website, <?php bloginfo('name'); ?>.  
This article was written on <?php the_time('jS F Y') ?>, in 
Seattle, Washington, and you can find similar articles in 
the <?php the_category(' and ') ?> categories, or more articles 
by <?php the_author_posts_link() ?>, if you enjoyed this article.  
If you have any comments about this article, you can contact 
<?php the_author() ?> by <a href="mailto:<?php the_author_email(); ?>">
email</a>, or leave a comment below.  You can also follow comments 
made on this article via our <?php comments_rss_link('RSS 2.0'); ?> 
feed.</p>
<p>If you would like to continue reading more, 
<?php previous_post('the previous article on our site is called %', ' ', 'yes', 'yes'); ?>
<?php next_post(' and the next article is called %', ' ', 'yes', 'yes'); ?>.
  Thank you for visiting our site.</p></div>

This example, if styled in a narrow column found on most sidebars, would look like this:

You are reading the article, WordPress Makes Me Smile, on our website, Talking Blog. This article was written on May 15, 2004, in Seattle, Washington, and you can find similar articles in the WordPress and Blog categories, or more articles by Harriet Smith, if you enjoyed this article. If you have any comments about this article, you can contact Harriet Smith by email, or leave a comment below. You can also follow comments made on this article via our RSS 2.0 feed. If you would like to continue reading more, the previous article on our site is called Things To Do With WordPress and the next article is called Why I Like WordPress. Thank you for visiting our site.

This is just the beginning. There are many ways you can style your post meta data; by putting it in a box, by making it part of the text, by having it in a list...it's up to your imagination how you want to style your post meta data, and what information you want to share with your public about your posts.

その他の情報

最新英語版: WordPress Codex » Post_Meta_Data_Section最新版との差分