[WordPress] 外掛分享: Parentless Categories

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

內容簡介

這個外掛提供了一個模板標籤,作為 WordPress 內建模板標籤the_category()的修改版本。 the_category()列出了直接指定給帖子的所有類別。 c2c_parentless_categories()則列出這些類別,排除父類別中有其他指定類別的類別。

例如,假設你的類別結構是層次化的,看起來像這樣:

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

如果你直接將類別「Fruiting」、「Cucumber」和「Pumpkin」指定給帖子,c2c_parentless_categories()會返回一個列表,該列表包含:「Cucumber」和「Pumpkin」。請注意,由於「Fruiting」是直接分配給其他類別的父類別,因此它不包含在列表中。

默認情況下,類別以 HTML 列表形式顯示。首個引數允許你定義自定義分隔符,例如:要顯示簡單的逗號分隔類別列表,可以使用:<?php c2c_parentless_categories( ',' ); ?>。

與通過the_category()列出的類別一樣,列出的類別以鏈接的形式呈現到各自的類別存檔頁面中。

範例用法(基於上面的範例):

<?php c2c_parentless_categories(); ?>

輸出類似於:

<ul><li><a href="http://yourblog.com/category/fruiting/cucumber">Cucumber</a></li>
<li><a href="http://yourblog.com/category/fruiting/pumpkin">Pumpkin</a></li></ul>

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

輸出類似於:

<a href="http://yourblog.com/category/fruiting/cucumber">Cucumber</a>, <a href="http://yourblog.com/category/fruiting/pumpkin">Pumpkin</a>

鏈接: 外掛首頁 | 外掛目錄頁面 | GitHub | 作者首頁

開發人員文檔

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

總的來說,這些是外掛提供的模板標籤:

c2c_parentless_categories():輸出無父類別的類別。
c2c_get_parentless_categories_list():返回無父類別的類別列表。
c2c_get_parentless_categories():返回指定帖子的無父類別的類別列表。

這些是外掛提供的鉤子:

c2c_parentless_categories(動作),c2c_get_parentless_categories_list,c2c_get_parentless_categories(過濾器):
允許以另一種方式安全地調用每個同名函數,以便如果禁用或刪除插件,則對函數的調用不會導致失敗。

外掛標籤

開發者團隊

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

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

原文外掛簡介

This plugin provides a template tag which acts as a modified version of WordPress’s built-in template tag, the_category(). the_category() lists all categories directly assigned to the specified post. c2c_parentless_categories() lists those categories, except for categories that are parents to other assigned categories.
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”, “Cucumber”, and “Pumpkin” to a post, c2c_parentless_categories() would return a list that consists of: “Cucumber”, and “Pumpkin”. Notice that since “Fruiting” was a parent to a directly assigned category, it is not included in the list.
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 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:
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_parentless_categories() : Outputs the parentless categories.
c2c_get_parentless_categories_list() : Returns the list of parentless categories.
c2c_get_parentless_categories() : Returns the list of parentless categories for the specified post.

These are the hooks provided by the plugin:

c2c_parentless_categories (action), c2c_get_parentless_categories_list, c2c_get_parentless_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_parentless_categories_list (filter) :
Customizes the return value of the c2c_parentless_categories_list() function.
c2c_get_parentless_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