has_post_format

函式
has_post_format ( $format = array(), $post = null )
引數
  • (string|string[]) $format Optional. The format or formats to check.
    Required:
    Default: array()
  • (WP_Post|int|null) $post Optional. The post to check. Defaults to the current post in the loop.
    Required:
    Default: null
返回值
  • (bool) True if the post has any of the given formats (or any format, if no format specified), false otherwise.
定義位置
相關方法
set_post_formatget_post_format_post_format_linkhas_post_parent_post_format_request
引入
3.1.0
棄用
-

has_post_format – 這是一個WordPress函式,用於檢查當前文章是否有一個特定的文章格式分配給它。文章格式是預定義的格式,可以用來以標準化的方式顯示不同型別的內容,如畫廊、視訊或音訊文章。has_post_format函式接收一個引數,即文章格式的名稱,如果文章有分配給它的格式,則返回true。

檢查一個文章是否有任何給定的格式,或任何格式。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function has_post_format( $format = array(), $post = null ) {
$prefixed = array();
if ( $format ) {
foreach ( (array) $format as $single ) {
$prefixed[] = 'post-format-' . sanitize_key( $single );
}
}
return has_term( $prefixed, 'post_format', $post );
}
function has_post_format( $format = array(), $post = null ) { $prefixed = array(); if ( $format ) { foreach ( (array) $format as $single ) { $prefixed[] = 'post-format-' . sanitize_key( $single ); } } return has_term( $prefixed, 'post_format', $post ); }
function has_post_format( $format = array(), $post = null ) {
	$prefixed = array();

	if ( $format ) {
		foreach ( (array) $format as $single ) {
			$prefixed[] = 'post-format-' . sanitize_key( $single );
		}
	}

	return has_term( $prefixed, 'post_format', $post );
}

常見問題

FAQs
檢視更多 >