前言介紹
- 這款 WordPress 外掛「WordPress Conditional Content」是 2013-12-01 上架。
- 目前有 70 個安裝啟用數。
- 上一次更新是 2013-12-02,距離現在已有 4170 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
- 外掛最低要求 WordPress 3.0 以上版本才可以安裝。
- 有 5 人給過評分。
- 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。
外掛協作開發者
外掛標籤
if | else | content | conditions | conditional |
內容簡介
4>使用方法
你可以在 if 簡碼(shortcode) 中放入條件式的內容,並使用其屬性來定義條件。簡碼之間的內容只有在所有已定義的條件都符合時才會顯示。
定義條件
條件是通過在簡碼的屬性中設置以下格式來定義的:
[if
條件式的內容
[/if]
一個基本的例子:
[if qs="product-type:shoes"]
謝謝你購買鞋子
[/if]
在這個例子中的文字只有在當前 URL 具有 GET 參數“product-type”並且該值為“shoes”時才會顯示。
可用的條件類型有:
qs – 匹配定義的查詢字符串/GET 參數的鍵/值對。查詢字符串條件的格式如下:
[if qs="
qskey 是查詢字符串變量的名稱,qsvalue 是要測試的值。例如,條件“qs="product-type:2"”將匹配“?product-type=2”。
referrer – 檢查當前來源網址。如果 HTTP_REFERER 包含
role – 匹配當前用戶的角色。匹配需要精確,因此“admin”將不匹配“administrator”。如果您想匹配未登錄的用戶,請使用空值的 role。
例子
根據查詢字符串顯示內容:
[if qs=”utm_source:partner-site”]
只有當當前 URL 包含 GET 參數 'utm_source' 並且其值為 'partner-site' 時才顯示此內容
[/if]
根據引薦網址顯示內容:
[if referrer="www.google.com"]
只有在引薦 URL 包含 'www.google.com' 時才顯示此內容
[/if]
根據用戶角色顯示內容:
[if role="editor"]
只有當用戶以角色 'editor' 登錄時才顯示此內容
[/if]
設置多個條件和結合不同類型的條件:
[if referrer="www.example.com" qs="utm_source:partner-site"]
此內容會顯示給來自 example.com 的用戶,他們點擊了來自我們的 RSS 給養的鏈接。
[/if]
使用“exact”或“contain”進行匹配
默認情況下,查詢字符串條件是根據簡碼中定義的精確值進行匹配的。如果想要更緩和的“通配符”匹配,可以添加一個值為“contain”的 match 屬性:
[if qs="product-type:cashmere-" match="contain"]
不錯的選擇!羊絨是一種絕妙的面料。
[/if]
這將匹配 ?product-type=cashmere-sweater 和 ?product-type=cashmere-coat。
在多個值上進行匹配
你可以使用分號作為分隔符,讓條件匹配多個值。例如:
[if qs="product-type:shoes;coat"]
這段文字顯示給買了漂亮的鞋子或時尚外套的人看。
[/if]
原文外掛簡介
How to use
You can place conditional content between if shortcodes, and use its attributes to define conditions. The content between the shortcodes will only be displayed if all defined conditions are met.
Defining conditions
Conditions are defined by setting the attributes of the shortcode in the following format:
[if
Conditional content
[/if]
A basic example:
[if qs="product-type:shoes"]
Thank you for buying shoes
[/if]
The text in this example will only be displayed if the current URL has a GET paramater of “product-type” with the value “shoes”.
Available condition types are:
qs – Match on the key/value pair of the defined query string/GET parameter. Query string conditions are formatted like this:
[if qs="
qskey is the name of the query string variable and `qsvalue` the value to test for. For example, the condition `qs="product-type:2"` will match `?product-type=2`.
referrer – To check on the current referrer. The condition will be true if HTTP_REFERER contains
role – Matches the current user’s role. The match needs to be exact so “admin” will not match “administrator”. Use role with and empty value if you want to match users that are not logged in.
Examples
Display content based on query string:
[if qs=”utm_source:partner-site”]
This content is only displayed if the current URL contains a GET paramater ‘utm_source’ with value ‘partner-site’
[/if]
Display content based on referrer:
[if referrer="www.google.com"]
This content is only displayed if the referring URL contains 'www.google.com'
[/if]
Display content based on user role:
[if role="editor"]
This content is only displayed if the user is logged in with the role 'editor'
[/if]
Setting multiple conditions and combining condition types:
[if referrer="www.example.com" qs="utm_source:partner-site"]
This content is displayed to users coming from example.com who clicked on a link originating from our RSS feed.
[/if]
Matching with `exact` or `contain`
By default query string conditions are matched on the exact value as defined in the shortcode. For looser ‘wildcard’ matching you can add a match attribute with the value contain:
[if qs="product-type:cashmere-" match="contain"]
Good choice! Cashmere is a wonderful fabric.
[/if]
This will match both ?product-type=cashmere-sweater and ?product-type=cashmere-coat
Matching on multiple values
You can have a condition match on multiple values by using the semicolon as a seperator when defining allowed values. Example:
[if qs="product-type:shoes;coat"]
This text is displayed for people who bought either a nice pair of shoes or a great fashionable coat.
[/if]
Nesting `if` statements
You can nest statements but you have to use iteration. This has to do with the limitations of the built-in shortcode API.
[if qs="tonight:the-night"]
Tonight's the night.
[if2 qs="future:beautiful"]
We create our own destiny every day we live.
[/if2]
[if2 qs="future:platic"]
I see sheets of plastic in your future.
[/if2]
[/if]
You can nest up to if4 (4 levels).
各版本下載點
- 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
- 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「WordPress Conditional Content」來進行安裝。
(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。
延伸相關外掛(你可能也想知道)
mobble 》mobble 提供了與您網站相關的手機條件函數,例如 is_iphone()、is_mobile() 和 is_tablet()。, CSS 媒體查詢非常適合創建響應式網頁設計,但它們並不總是提供...。
If-So Dynamic Content Personalization 》個性化任何內容!根據訪客的個人資料或與網站的互動添加或替換內容。, 無需編程!, 創建動態內容的四種方式, , 條件觸發器-適用於每個頁面生成器-查看, 條件G...。
Elementor Element Condition 》這個外掛程式增加了在區塊和小工具中新增條件,以決定是否顯示。, 您可以使用 add_filter() 在您的 function.php 中新增自己的值。, 目前該插件相當基本,您...。
If-So Conditional Content for Elementor 》### 總結:輕鬆個性化,就在 Elementor 內部, - 輕鬆為訪客打造個性化體驗,根據位置、行為、搜索關鍵詞等動態調整 Elementor 頁面。, - 針對每位訪客量身定...。
Elementor Forms Conditional Logic 》總結文案:建立能隨著使用者填寫表單而變化的動態表單。顯示或隱藏欄位。發送某些郵件,不發送其他郵件。重定向到多個頁面。可能性無窮!, , - 特點:, - ...。
Block Logic – Full Gutenberg Block Display Control 》Block Logic 外掛在區塊編輯器(即 Gutenberg)的「進階」區段中添加了一個名為「Block Logic」的欄位,讓您可以根據條件顯示或隱藏任何區塊。您可以使用 Wor...。
Display During Conditional Shortcode 》輸入開始和結束日期/時間,您希望短碼內容在期間內顯示。選擇性地包括一個訊息或不同的內容,以便時間過去後顯示。, 短碼:, 將[display_during end_day_time...。
Extra Shipping Rates for WooCommerce 》
WordPress 外掛介紹:Extra Shipping Rates
,想要擺脫繁瑣的運費設定和固定價格結構嗎?別再猶豫!來認識一下 Extra Shipping...。
If Shortcode 》此外掛提供了「if」縮短碼來有條件地渲染內容。其語法如下:, [if condition1 condition2=false condition3]{content}[/if], , 條件作為屬性名稱傳遞。多個條...。
Conditional Tags Shortcode 》使用此簡碼,您可以控制內容顯示的位置。, 使用方法, 您可以使用 WordPress 提供的所有條件標籤。請查看下面的示例。, 僅在首頁上顯示文字:, [if is_fro...。
Composite Products – Conditional Images 》這是一款免費的小型外掛程式,適用於WooCommerce Composite Products,可以創建動態的、多層次的複合產品圖片,並根據選項更改進行響應。此外掛程式利用場景...。
GamiPress – Conditional Emails Recipients 》GamiPress - Conditional Emails Recipients 可讓您在 GamiPress - Conditional Emails 外掛中設置的電子郵件上添加自定義收件人!, 例如,當使用者解鎖特定...。
Block Control 》你是否曾經使用WordPress的新區塊編輯器 Gutenberg,希望有一種方式可以控制區塊顯示的時間和對象?我們曾經遇到這樣的情況,這就是為什麼我們推出了 Block C...。
ACF Conditional Logic Extended 》這款 WordPress 外掛可以擴展「群組欄位」的條件邏輯,提供一組額外的規則,並將選項值作為你的條件。, 支援欄位類型:, – 文字, – 大小文本框...。
WP Conditional Shortcodes 》這個外掛為內容開發人員提供了類似於 WordPress 主題開發提供的條件標籤的短碼。每個短碼只在特定條件為真時包括其內容。這使得他們能夠根據每個帖子的情況修...。