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

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

投稿フォーマット

提供: WordPress Codex 日本語版
2010年11月12日 (金) 20:09時点におけるBono (トーク | 投稿記録)による版 (3.1: en:Post Formats 11:01, 12 November 2010 Bono 版を翻訳用にコピー)

(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先: 案内検索

このページ「投稿フォーマット」は未翻訳です。和訳や日本語情報を加筆してくださる協力者を求めています

Post Formats, introduced with Version 3.1, are meta information that can be used by themes to customize presentation of a post. The basic idea is to

provide a specific method for specifying the display "format" of a post. This replaces the need to use categories to accomplish the same thing, and even more importantly, is portable between themes that support those formats!

Using Asides as an example, in the past, a category called Asides was created, and posts were assigned that category, and then displayed differently based on styling rules from post_class() or from in_category('asides').

With Post Formats, the new approach allows a theme to define a Post Format (e.g. add_theme_support('post-formats', array( 'aside'))), and then the post format can be selected in the Publish meta box when saving the post. A function call of get_post_format( $post->ID ) can be used to determine the format, and post_class() will also create the "format-asides" class, for pure-css styling.

The following Post Formats are supported.

  • aside - Typically styled without a title. Similar to a Facebook note update.
  • chat - A chat transcript, like so:
John: foo
Mary: bar
John: foo 2
  • gallery - A gallery of images.
  • link - A link to another site. The first <a href=””> tag in the post content will be considered the external link for that post. Alternatively, if the post consists only of a URL, that will be the URL and the title (post_title) will be the name.
  • image - A single image. The first <img /> tag in the post will be considered the image. Alternatively, if the post consists only of a URL, that will be the image URL and the title of the post (post_title) will be the title attribute for the image.
  • quote - A quotation. Suggested UI is a quote text area and a citation textarea. The quote should be saved to post_content as <blockquote>$quote_wrapped_with_paragraphs<p><cite>$citation</cite></p></blockquote>.
  • status - A short status update, usually limited to 140 characters. Similar to a Twitter status update.
  • video - A single video. The first <video /> tag or object/embed in the post content will be considered the video. Alternatively, if the post consists only of a URL, that will be the video URL.

Themes and plugins can set the format with set_post_format() and retrieve the format with get_post_format().

Adding Theme Support

Themes need to use add_theme_support() to tell WordPress which post formats to support by passing an array of formats like so:

add_theme_support( 'post-formats', array( 'aside', 'gallery' ) );

Then, in the theme, make use of get_post_format() to check the format for a post, and change its presentation accordingly. Note that posts with the default format will return a value of FALSE. Or make use of the conditional tag has_post_format():

if ( has_post_format( 'video' ) {
  echo 'this is the video format';
}

Backwards Compatibility

If your plugin or theme needs to be compatible with earlier versions of WordPress, you need to add terms named post-format-$format to the "post_format" taxonomy. For example,

wp_insert_term('post-format-aside', 'post_format');

You must also register the post_format taxonomy with register_taxonomy().

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