[WordPress] 外掛分享: Conditional Tags Shortcode

首頁外掛目錄 › Conditional Tags Shortcode
100+
安裝啟用
★★★★★
5/5 分(2 則評價)
2107 天前
最後更新
問題解決
WordPress 3.1+ v0.2 上架:2015-01-27

內容簡介

使用此簡碼,您可以控制內容顯示的位置。

使用方法

您可以使用 WordPress 提供的所有條件標籤。請查看下面的示例。

僅在首頁上顯示文字:
[if is_front_page] The text [/if]

僅在該網站的“關於”頁面上顯示文字:
[if is_page=”about”] The text [/if]

僅在分類存檔視圖中顯示:
[if is_category] The text [/if]

您可以在條件標籤前添加“not_”,以反轉邏輯,例如:
除首頁外,顯示該網站的所有頁面:
[if not_is_front_page] The text [/if]

OR

使用多個參數,當滿足任一條件(“OR”比較)時顯示內容,例如,在類別和標籤存檔頁面上顯示文本:
[if is_category is_tag] The text [/if]

AND

您可以嵌套簡碼來設置多個條件,例如僅在首頁上且用戶已登錄時顯示文字:
[if is_user_logged_in][if is_front_page] The text [/if][/if]

僅在單個文章頁面上且僅在移動裝置上顯示到 WordPress.org 網站的鏈接:
[if wp_is_mobile][if is_single] WordPress [/if][/if]

has_term_{taxonomy}

您可以使用此功能檢查當前帖子是否屬於所需分類法定期內的自訂術語。參見:https://codex.wordpress.org/Function_Reference/has_term

例如,檢查當前帖子是否在“genre”分類法定期內具有“爵士”術語:
[if has_term_genre=”jazz”] The text [/if]

外掛標籤

開發者團隊

⬇ 下載最新版 (v0.2) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「Conditional Tags Shortcode」→ 直接安裝(推薦)

原文外掛簡介

With this shortcode you can take control of where the content is displayed.
Usage
You can use all the conditional tags WordPress provides. Checkout examples below.
Show text only on the homepage:
[if is_front_page] The text [/if]
Show text only on the About page of the site:
[if is_page=”about”] The text [/if]
Show only on the category archive view:
[if is_category] The text [/if]
You can add “not_” before the conditional tag to reverse the logic, example:
Show on all pages of the site except the homepage:
[if not_is_front_page] The text [/if]
OR
Using multiple parameters, the content is displayed when either of the conditions are met (“OR” comparison), for example, show text on both category and tag archive pages:
[if is_category is_tag] The text [/if]
AND
To set multiple conditions you can nest the shortcode, for example show text only on homepage AND if the user is logged in:
[if is_user_logged_in][if is_front_page] The text [/if][/if]
Show a link to wordpress.org site, only on single post pages and only on mobile devices:
[if wp_is_mobile][if is_single] WordPress [/if][/if]
has_term_{taxonomy}
You can use this to check if the current post in the loops belongs to a custom term in the desired taxonomy. See: https://codex.wordpress.org/Function_Reference/has_term
Example, check if current post has the “jazz” term in the “genre” taxonomy:
[if has_term_genre=”jazz”] The text [/if]

延伸相關外掛

文章
Filter
Apply Filters
Mastodon