這個外掛並未在最新的 3 個 WordPress 主要版本上進行測試。開發者可能不再對這個外掛進行維護或提供技術支援,並可能會與更新版本的 WordPress 產生使用上的相容性問題。

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]

安裝方式

  1. Upload the menu-item-visibility directory to the /wp-content/plugins/ directory
  2. Activate the plugin through the ‘Plugins’ menu in WordPress
  3. Enjoy!

使用者評論

2016 年 9 月 3 日
Such a clever solution to create the code in a way that it doesn't need to be updated as it will accept all the conditional tags that wordpress provides. It will work as long as wordpress don't change their syntax ...
閱讀全部 2 則使用者評論

參與者及開發者

以下人員參與了開源軟體〈Conditional Tags Shortcode〉的開發相關工作。

參與者

將〈Conditional Tags Shortcode〉外掛本地化為台灣繁體中文版

對開發相關資訊感興趣?

任何人均可瀏覽程式碼、查看 SVN 存放庫,或透過 RSS 訂閱開發記錄