has_category

函式
has_category ( $category = '', $post = null )
引數
  • (string|int|array) $category Optional. The category name/term_id/slug, or an array of them to check for. Default empty.
    Required:
    Default: (empty)
  • (int|WP_Post) $post Optional. Post to check. Defaults to the current post.
    Required:
    Default: null
返回值
  • (bool) True if the current post has any of the given categories (or any category, if no category specified). False otherwise.
定義位置
相關方法
is_categorythe_categoryin_categoryget_categorythe_category_id
引入
3.1.0
棄用
-

has_category – 這是一個WordPress函式,用於檢查是否有一個特定的類別被分配給當前的文章。分類是用來將網站上的內容組織成不同的主題或課題。has_category函式接受一個引數,即類別的名稱或ID,如果該文章有分配給它的類別,則返回true。

檢查當前文章是否有任何給定的類別。

給定的類別將與文章的類別的術語、名稱和片語進行檢查。以整數形式給出的類別將只與文章的類別的 term_ids 進行檢查。

如果沒有給定類別,則確定文章是否有任何類別。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function has_category( $category = '', $post = null ) {
return has_term( $category, 'category', $post );
}
function has_category( $category = '', $post = null ) { return has_term( $category, 'category', $post ); }
function has_category( $category = '', $post = null ) {
	return has_term( $category, 'category', $post );
}

常見問題

FAQs
檢視更多 >