get_post_format

函式
get_post_format ( $post = null )
引數
  • (int|WP_Post|null) $post Optional. Post ID or post object. Defaults to the current post in the loop.
    Required:
    Default: null
返回值
  • (string|false) The format if successful. False otherwise.
定義位置
相關方法
set_post_formatget_post_format_linkget_post_format_slugsget_post_format_stringhas_post_format
引入
3.1.0
棄用
-

get_post_format函式返回文章的格式。文章格式是區分不同型別內容的一種方式,如標準、旁白、相簿、視訊、音訊等。此功能採用一個引數,即文章的ID。如果文章沒有格式,則此函式返回false。

檢索一個文章的格式slug。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function get_post_format( $post = null ) {
$post = get_post( $post );
if ( ! $post ) {
return false;
}
if ( ! post_type_supports( $post->post_type, 'post-formats' ) ) {
return false;
}
$_format = get_the_terms( $post->ID, 'post_format' );
if ( empty( $_format ) ) {
return false;
}
$format = reset( $_format );
return str_replace( 'post-format-', '', $format->slug );
}
function get_post_format( $post = null ) { $post = get_post( $post ); if ( ! $post ) { return false; } if ( ! post_type_supports( $post->post_type, 'post-formats' ) ) { return false; } $_format = get_the_terms( $post->ID, 'post_format' ); if ( empty( $_format ) ) { return false; } $format = reset( $_format ); return str_replace( 'post-format-', '', $format->slug ); }
function get_post_format( $post = null ) {
	$post = get_post( $post );

	if ( ! $post ) {
		return false;
	}

	if ( ! post_type_supports( $post->post_type, 'post-formats' ) ) {
		return false;
	}

	$_format = get_the_terms( $post->ID, 'post_format' );

	if ( empty( $_format ) ) {
		return false;
	}

	$format = reset( $_format );

	return str_replace( 'post-format-', '', $format->slug );
}

常見問題

FAQs
檢視更多 >