[WordPress] 外掛分享: Limit taxonomy term count

首頁外掛目錄 › Limit taxonomy term count
WordPress 外掛 Limit taxonomy term count 的封面圖片
全新外掛
安裝啟用
★★★★★
5/5 分(1 則評價)
2702 天前
最後更新
問題解決
WordPress 4.7+ PHP 5.6+ v1.0 上架:2018-10-22

內容簡介

WordPress 預設不允許您限制聯結到文章的分類法(term)數量。
啟用此外掛程式,將可在初始化呼叫 register_taxonomy() 時使用「限制」屬性。
如果限制設為1,則只能添加一個分類法至文章。如果限制大於1,就可以添加該數量的分類法至文章。如果未設置限制屬性,或設為 -1,此外掛程式將不會產生影響。

以下為示範程式碼,展示如何使用限制屬性:

register_taxonomy('artists', 'art_work', [
'label' => 'Artists',
'show_ui' => true,
'limit' => 1,
]);

此範例展示如何使用名為「artists」自訂分類法,並使用的文章類型為「art_work」。

以下是另一個範例,這次是編輯先前註冊的分類法「post_tag」:

// 首先載入分類法
$taxonomy = get_taxonomy('post_tag');

// 現在將其編輯為每篇文章只能添加2個標籤
$taxonomy->limit = 2;

// 最後,使用我們更新過的設定 (請注意在進行註冊之前將物件轉換為矩陣)
register_taxonomy('post_tag', 'post', (array)$taxonomy);

外掛標籤

開發者團隊

⬇ 下載最新版 (v1.0) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「Limit taxonomy term count」→ 直接安裝(推薦)
📦 歷史版本下載

原文外掛簡介

By default WordPress does not allow you to limit how many taxonomy terms can be attached to a post.
Enabling this plugin allows the use of the “limit” attribute when initially calling register_taxonomy().
If the limit is set to 1 then only one term can be added to the post. If the limit is greater than one then that many
terms may be added to the post. If the limit is attribute is not set, or it’s set to -1 this plugin has no effect.
Example code showing the use of the limit attribute:
register_taxonomy('artists', 'art_work', [
'label' => 'Artists',
'show_ui' => true,
'limit' => 1,
]);

This example shows the use of a custom taxonomy called “artists” and the post type is “art_work”.
Here is another example but this time it’s editing the previously registered taxonomy “post_tag”:
// First load the taxonomy
$taxonomy = get_taxonomy('post_tag');

// Edit it to only allow 2 tags to be added per post
$taxonomy->limit = 2;

// Re-save it with our updated settings (note casting the object to an array before saving)
register_taxonomy('post_tag', 'post', (array)$taxonomy);

延伸相關外掛

文章
Filter
Apply Filters
Mastodon