has_tag

函式
has_tag ( $tag = '', $post = null )
引數
  • (string|int|array) $tag Optional. The tag 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 tags (or any tag, if no tag specified). False otherwise.
定義位置
相關方法
has_metais_taghas_termthe_tagshas_category
引入
2.6.0
棄用
-

has_tag – 這是一個WordPress的函式,用來檢查當前文章是否有任何標籤分配給它。標籤是一個關鍵詞或短語,用來對網站的內容進行分類和組織。如果當前文章至少有一個標籤分配給它,has_tag函式返回true,如果沒有則返回false。

檢查當前文章是否有任何給定的標籤。

給出的標籤將與文章的標籤的 term_ids、名稱和 slugs 進行核對。以整數形式給出的標籤將只與文章的標籤 term_ids 進行檢查。

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

關於這個和類似的主題功能的更多資訊,請檢視《主題開發者手冊》中的{@link Conditional Tags}文章。

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

常見問題

FAQs
檢視更多 >