前言介紹
- 這款 WordPress 外掛「Conditional Custom Fields Shortcode」是 2009-07-29 上架。
- 目前有 20 個安裝啟用數。
- 上一次更新是 2009-07-30,距離現在已有 5759 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
- 外掛最低要求 WordPress 2.7 以上版本才可以安裝。
- 尚未有人給過這款外掛評分。
- 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。
外掛協作開發者
oltdev | godfreykfc |
外掛標籤
cms | template | shortcode | conditional | custom fields |
內容簡介
一系列的短代码,可在页面或文章中(或通过小部件中的侧栏小部件-通过Section Widget!)使用自定义字段值,这将允许您将实际数据存储在自定义字段中,同时将演示内容存储在页面/文章正文中,将WordPress转变为了一款强大的CMS。继续阅读获取更多灵感。
基本用法
[cf "自定义字段名称"]
例如:
今日图片:
将输出类似于
,假设帖子/页面具有自定义字段“图片链接”,其值为“http://thesite.com/something.jpg”。这样,您(或您的客户)更新页面时不会意外删除div,因为您不再需要修改页面/文章正文!
默认值
[cf "自定义字段名称" default="如果CF未定义,请显示此内容"]
例如:
如果您有任何问题,请联系[cf "support-email" default="[email protected]"]。
如果帖子/页面中不存在自定义字段“support-email”,则将在那里显示“[email protected]”。
简单模板
[cf "自定义字段名称" default="默认值"]...模板...[/cf]
例如:
价格:[cf "price" default="尚未提供定价信息。"] 美元%value% [/cf]
如果由于某种原因无法使用%value%作为占位符文本,您可以通过指定占位符属性来更改它。
例如:
价格:[cf "price" default="尚未提供定价信息。" placeholder="__value__"] 美元$__value__ [/cf]
多个值
它很聪明,能够做正确的事情。如果您的帖子具有以下自定义字段:
音乐会日期:1月14日
音乐会日期:1月28日
音乐会日期:2月2日
那么[cf "音乐会日期"]将输出Jan 14th,Jan 28th,Feb2nd,正是您所期望的。您还可以可选地提供分隔符以替换默认值(,)。
例如:
在以下日期中的任何一个到我们的音乐会:[cf "音乐会日期" separator=" / "]
结果为(=> Jan 14th / Jan 28th / Feb 2nd)
排序
[cf "自定义字段名称" sort="nosort|asc|dsc|random" type="string|int|integer|float|bool|boolean|date|auto"]
您可以使用sort属性(默认为nosort)控制如何对项目进行排序(当有多个项目时)。默认情况下,它将使用PHP的比较运算符进行比较(即尝试将其转换为数字值,如果失败则将其作为字符串进行比较)。但是,您可以通过指定type属性(默认值为auto)强制进行类型转换。
显示单个值
如果显示多个值不是您想要的,您可以使用[cf single="true"]强制只显示第一个值。将我们学到的内容结合起来,您可以通过[cf single="true" sort="random"]显示单个随机值。
摘要
[cf]短代码的语法:(默认值在括号内)
[cf "field-name" default="" placeholder="%value%" single="(false)|true" separator="," sort="(nosort)|asc|dsc|random" type="string|int|integer|float|bool|boolean|date|(auto)"](OPTIONAL) template[/cf]
原文外掛簡介
A series of shortcodes for using custom field values in pages or posts (or in sidebar widgets – via Section Widget!), which would then allows you to take store the actual data in custom fields while storing the presentation in the page/post body. This transforms WordPress into an awesome CMS. Keep reading for more inspirations.
Basic Usage
[cf "custom field name"]
Example:
Picture of the day:
This would output something like
, assume the post/page has the custom field “picture-link” and its value is “http://thesite.com/something.jpg”. That way, you (or your clients!) would never accidentally take out a div when updating your page because you won’t have to touch the page/post body anymore!
Default Values
[cf "custom field name" default="display this if the CF is undefined"]
Example:
Contact [cf "support-email" default="[email protected]"] if you have questions.
[email protected] will be displayed there if the custom field “support-email” is not present in that post/page.
Simple Template
[cf "custom field name" default="default value"]...template...[/cf]
Example:
Price: [cf "price" default="Pricing information not available yet."] USD$%value% [/cf]
If you cannot use %value% as your placeholder text for some reason, you can change it by specifying the placeholder attribute.
Example:
Price: [cf "price" default="Pricing information not available yet." placeholder="__value__"] USD$__value__ [/cf]
Multiple Values
It’s smart enough to do the right thing. If your post has the following custom fields:
concert-date: Jan 14th
concert-date: Jan 28th
concert-date: Feb 2nd
Then [cf "concert-date"] will output Jan 14th,Jan 28th,Feb2nd, exactly what you would expect. You can also optionally provide a separator to replace the default (,).
Example:
Come to one of our concerts on the following dates: [cf "concert-date" separator=" / "]
(=> Jan 14th / Jan 28th / Feb 2nd)
Sorting
[cf "custom field name" sort="nosort|asc|dsc|random" type="string|int|integer|float|bool|boolean|date|auto"]
You can control how it sort the items (when there’s more than one) using the sort attribute (default is nosort). By default, it would compare them using PHP’s comparison operator (i.e. try to cast them into numeric values, or compare them as strings if that failed). However, you can force a type cast by specifying the type attribute (default is auto).
Display Single Value
If display multiple values is not what you want it to do, you can use [cf single="true"] to force it to display only the first value. Combining what we have learned so far, you can display a single random value by [cf single="true" sort="random"].
Summary
Syntax for [cf] shortcode: (default values in parenthesis)
[cf "field-name" default="" placeholder="%value%" single="(false)|true" separator="," sort="(nosort)|asc|dsc|random" type="string|int|integer|float|bool|boolean|date|(auto)"](OPTIONAL) template[/cf]
Conditionals
Conditionals tags is what makes this plugin unique. Here is a list of them:
[if-cf-def "custom field name"]
Do this when "custom field name" is defined for this page/post
[/if-cf-def]
[if-cf-ndef "custom field name"]
Do this when "custom field name" is NOT defined for this page/post
[/if-cf-ndef]
[if-cf-eq "custom field name" "value"]
Do this when "custom field name" == "value"
[/if-cf-eq]
[if-cf-neq "custom field name" "value"]
Do this when "custom field name" != "value"
[/if-cf-neq]
[if-cf-lt "custom field name" "value"]
Do this when "custom field name" "value"
[/if-cf-gt]
[if-cf-let "custom field name" "value"]
Do this when "custom field name" = "value"
[/if-cf-get]
More detailed documentations will be published soon. In the mean time, check out the following examples and the comments in the PHP code to get a rough idea.
Examples
[if-cf-get "deadline" "today" type="date"]
Submit your application here.
[/if-cf-get]
[if-cf-lt "deadline" "today" type="date"]
Sorry we regret that we cannot take anymore applications.
[/if-cf-lt]
[if-cf-def "discounted-price" "discount-expires" logic="and"]
This product is on discount, get it now for [cf "discounted-price" /] [cf "discount-expires" default="for a limited time"]before %value%[/cf]!
[/if-cf-def]
Please note: It seems that there is a serious bug in WordPress’ shortcode parser that prevents shortcodes from functioning correctly in certain occasions. The developers are hard at work to get this fixed before the 2.8.3 release. (See #10082) Therefore, please do not report any parser related bugs for the moment. (e.g. the shortcode is displayed on the actual page)
各版本下載點
- 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
- 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「Conditional Custom Fields Shortcode」來進行安裝。
(建議使用方法二,確保安裝的版本符合當前運作的 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 頁面。, - 針對每位訪客量身定...。
Conditional Logic for Elementor Forms 》總結文案:建立能隨著使用者填寫表單而變化的動態表單。顯示或隱藏欄位。發送某些郵件,不發送其他郵件。重定向到多個頁面。可能性無窮!, , - 特點:, - ...。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...。
WordPress Conditional Content 》4>使用方法, 你可以在 if 簡碼(shortcode) 中放入條件式的內容,並使用其屬性來定義條件。簡碼之間的內容只有在所有已定義的條件都符合時才會顯示。, 定義...。
ACF Conditional Logic Extended 》這款 WordPress 外掛可以擴展「群組欄位」的條件邏輯,提供一組額外的規則,並將選項值作為你的條件。, 支援欄位類型:, – 文字, – 大小文本框...。
