万が一、当サイトで重大な問題を発見した際などは、フォーラムや WordSlack #docs チャンネルでお知らせください。</p>
関数リファレンス/get post format
説明
投稿記事の投稿フォーマットを返します。 これは通常ループ内で呼び出されますが、投稿IDが提供されていれば、どこでも使うことができます。
使い方
<?php $format = get_post_format( $post_id ); ?>
パラメータ
- $post_id
- (integer) (Optional) 投稿のID
- 初期値: 現在のループ記事
返り値
- Format (string)
- 投稿のフォーマット、フォーマットが設定されていない場合 falseを返す。
現在定義されているフォーマット:
- aside
- chat
- gallery
- link
- image
- quote
- status
- video
- audio
デフォルトのフォーマット(例、通常の投稿)がfalseを返しますが、しかし'標準'フォーマットとしていくつかの場所で呼ばれることに注意しましょう。
いくつかのケースでは、開発者が何かを一貫性を維持するために、以下のように記述します:
$format = get_post_format(); if ( false === $format ) { $format = 'standard'; }
用例
<?php /* * Pull in a different sub-template, depending on the Post Format. * * Make sure that there is a default '<tt>format.php</tt>' file to fall back to * as a default. Name templates '<tt>format-link.php</tt>', '<tt>format-aside.php</tt>', etc. * * You should use this in the loop. */ $format = get_post_format(); get_template_part( 'format', $format ); ?>
更新履歴
- 新規導入: 3.1
ソースファイル
get_post_format() は wp-includes/post-formats.php
にあります。
外部リソース
- Post types and formats and taxonomies, oh my! by Otto
- WordPress 3.1 Post Formats Reference by Lisa Sabin-Wilson
- Smarter Post Formats? by Dougal Campbell
- Smarter Post Formats? Use Carrington by Alex King
関連
投稿フォーマット: set_post_format(), get_post_format(), has_post_format(), the_post_format_audio() /en, get_the_post_format_media() /en, get_content_audio() /en, the_post_format_chat() /en, get_the_post_format_chat() /en, get_content_chat() /en, add_chat_detection_format() /en, the_post_format_gallery() /en, get_content_galleries() /en, get_post_gallery_images(), the_post_format_image() /en, get_the_post_format_image() /en, get_content_images() /en, the_post_format_quote() /en, get_the_post_format_quote() /en, get_content_quote() /en, the_post_format_url() /en, get_the_post_format_url() /en, get_content_url() /en, the_post_format_video() /en, get_content_video() /en, the_remaining_content() /en, get_the_remaining_content() /en, get_post_format_meta() /en, post_format_content_class() /en, get_post_format_content_class() /en, post_formats_compat() /en
最新英語版: WordPress Codex » Function_Reference/get post format (最新版との差分)