[WordPress] 外掛分享: Peer Categories

首頁外掛目錄 › Peer Categories
WordPress 外掛 Peer Categories 的封面圖片
10+
安裝啟用
尚無評分
330 天前
最後更新
問題解決
WordPress 4.6+ v2.3.1 上架:2009-06-11

內容簡介

這個外掛提供了一個模板標籤,作為 WordPress 內建模板標籤 the_category() 的修改版本。 the_category() 列出直接分配給指定文章的所有類別。 c2c_peer_categories() 列出這些類別,以及同級類別中的任何類別,除了其他分配類別的父類別。同級類別是共享相同類別的父類別的類別。

例如,假設您的類別結構是階層式的,看起來像這樣:

Vegetables
|-- Leafy
| |-- Broccoli
| |-- Bok Choy
| |-- Celery
|-- Fruiting
| |-- Bell Pepper
| |-- Cucumber
| |-- Pumpkin
|-- Podded
| |-- Chickpea
| |-- Lentil
| |-- Soybean

如果您直接分配給文章的分別是 "Fruiting" 和 "Pumpkin" 類別,peer_categories() 會返回由 "Bell Pepper"、"Cucumber" 和 "Pumpkin" 組成的列表。 注意,由於 "Fruiting" 是直接分配類別的父類別,因此它及其同級類別未包含在列表中。 如果只有 "Fruiting" 作為類別被選擇,則將列出 "Leafy"、"Fruiting" 和 "Podded"。

預設情況下,分類被列為 HTML 列表。 模板標籤的第一個引數允許您定義自定義分隔符,例如,簡單的逗號分隔的同級類別列表: <?php c2c_peer_categories(','); ?>。

與 the_category() 列出的類別一樣,列出的類別是作為連結顯示到相應類別的存檔頁面。

範例用法(基於上例):

<?php c2c_peer_categories(); ?>

輸出類似以下內容:

<ul><li><a href="https://example.com/category/fruiting/bell-pepper">Bell Pepper</a></li>
<li><a href="https://example.com/category/fruiting/cucumber">Cucumber</a></li>
<li><a href="https://example.com/category/fruiting/pumpkin">Pumpkin</a></li></ul>

<?php c2c_peer_categories( ',' ); ?></ul>

輸出類似以下內容:

<a href="https://example.com/category/fruiting/bell-pepper">Bell Pepper</a>, <a href="https://example.com/category/fruiting/cucumber">Cucumber</a>, <a href="https://example.com/category/fruiting/pumpkin">Pumpkin</a>

連結:外掛首頁 | 外掛目錄頁面 | GitHub | 作者首頁

開發人員文件

可以在 DEVELOPER-DOCS.md 中找到開發人員文件。該文件涵蓋了插件提供的模板標籤和鉤子。

簡而言之,這些是外掛提供的模板標籤:

c2c_peer_categories():輸出同級類別。
c2c_get_peer_categories_list():返回同級類別列表。
c2c_get_peer_categories():返回指定文章的同級類別列表。

這些是提供的鉤子

外掛標籤

開發者團隊

⬇ 下載最新版 (v2.3.1) 或搜尋安裝

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

原文外掛簡介

This plugin provides a template tag which acts a modified version of WordPress’s built-in template tag, the_category(). the_category() lists all categories directly assigned to the specified post. c2c_peer_categories() lists those categories PLUS any categories that are peer to those categories and MINUS categories that are parents to other assigned categories. Peer categories are categories that all share the same category parent.
For example, assume your category structure is hierarchical and looks like this:
Vegetables
|-- Leafy
| |-- Broccoli
| |-- Bok Choy
| |-- Celery
|-- Fruiting
| |-- Bell Pepper
| |-- Cucumber
| |-- Pumpkin
|-- Podded
| |-- Chickpea
| |-- Lentil
| |-- Soybean

If you directly assigned the categories “Fruiting” and “Pumpkin” to a post, peer_categories() would return a list that consists of: “Bell Pepper”, “Cucumber”, and “Pumpkin”. Notice that since “Fruiting” was a parent to a directly assigned category, it and its peers are not included in the list. If only “Fruiting” were selected as a category, then “Leafy”, “Fruiting”, and “Podded” would have been listed.
By default, categories are listed as an HTML list. The first argument to the template tag allows you to define a custom separator, e.g. to have a simple comma-separated list of peer categories: .
As with categories listed via the_category(), categories that are listed are presented as links to the respective category’s archive page.
Example usage (based on preceding example):

Outputs something like:

Outputs something like:
Bell Pepper, Cucumber, Pumpkin

Links: Plugin Homepage | Plugin Directory Page | GitHub | Author Homepage
Developer Documentation
Developer documentation can be found in DEVELOPER-DOCS.md. That documentation covers the template tags and hooks provided by the plugin.
As an overview, these are the template tags provided by the plugin:

c2c_peer_categories() : Outputs the peer categories.
c2c_get_peer_categories_list() : Returns the list of peer categories.
c2c_get_peer_categories() : Returns the list of peer categories for the specified post.

These are the hooks provided by the plugin:

c2c_peer_categories (action), c2c_get_peer_categories_list, c2c_get_peer_categories (filters) :
Allows for an alternative approach to safely invoke each of the identically named functions in such a way that if the plugin were deactivated or deleted, then your calls to the functions won’t cause errors on your site.
c2c_peer_categories_list (filter) :
Customizes the return value of the c2c_peer_categories_list() function.
c2c_get_peer_categories_omit_ancestors (filter) :
Customizes the function argument indicating if ancestor categories of all directly assigned categories (even if directly assigned themselves) should be omitted from the return list of categories.

延伸相關外掛

文章
Filter
Mastodon