get_post_format

Sponsored Link

記事の投稿フォーマットを返します。これは通常ループ内で呼び出されますが、投稿IDが提供されていればどこでも使用することができます。

Returns the post format of a post. This will usually be called in the the loop, but can be used anywhere if a post ID is provided.

get_post_formatのファンクションタグ使用方法

<?php $format = get_post_format( $post_id ); ?>

get_post_formatのパラメーター

$post_id

(integer) (Optional)投稿のID。
デフォルト:現在のループ記事

(integer) (Optional) ID of the post.
Default: current loop post

Returns

Format (string)

投稿のフォーマットが、全くフォーマットが設定されていない場合は、false。
現在定義されている形式のセットは、次のとおりです。

The format of the post, or false if no format is set.
The set of currently defined formats is:

  • aside
  • chat
  • gallery
  • link
  • image
  • quote
  • status
  • video
  • audio

デフォルトのフォーマット(例、通常の投稿)がfalseを返すが、これは’標準’フォーマットとしていくつかの場所で呼ばれることにも注意してください。いくつかのケースでは、開発者が以下のような一貫性を維持するための何かをしたい場合:

Note also that the default format (i.e., a normal post) returns false, but this is also referred in some places as the ‘standard’ format. In some cases, developers may wish to do something like the following to maintain consistency:

$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 );
?>

変更ログ

Since: 3.1

ソースファイル

get_post_format()は、wp-includes/post.php内に位置しています。

get_post_format() is located in wp-includes/post.php.

External Resources

  • 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

関連ファンクションタグ

Post Formats: set_post_format(), get_post_format(), has_post_format()

get_query_template

拡張子を使用せずにファイルのパスを取得します。

ファイルの拡張子を含まないファイルのパスを直接取得するために使用します。locate_template()の使用でファイルが存在する場合、親テンプレートのチェックもします。他のget_*_template()関数の使用することなくより汎用的なファイルの場所が可能となります。

パスを取得するためにinclude()あるいはrequire()を使用することができます。

Continue reading

Sponsored Link