[WordPress] 外掛分享: Elevate Parent Category Template

首頁外掛目錄 › Elevate Parent Category Template
30+
安裝啟用
尚無評分
5484 天前
最後更新
問題解決
WordPress 2.5+ v1.0.4 上架:2008-08-02

內容簡介

此外掛可提供函數來取得指定文章的母類別(父類別)資訊,若該文章被歸入於母類別的子類別中。

透過這個功能,此外掛也能夠修改 WordPress 迴圈(Loop)並將產生任何類別頁面的操作重新定向至母類別。這對於主題開發人員希望能夠指定 category-x.php 模板並讓所有相關文章,無論是指定到該類別或其子類別,都使用該模板進行頁面產生的情況非常有用。

舉例來說,目前的類別結構如下:

主類別(已設有 category-x.php 模板)

子類別 1
子類別 2

一篇文章被指定到『子類別 2』中。

當該文章被請求時,此外掛將會自動檢測是否有母類別。若有,它將會修改 WP 變數,將當前類別設為母類別,同時添加一個新變數,指出該文章實際所處類別。這會影響 WordPress 迴圈,使其使用父類別定義的 category-x.php 模板。

主題開發人員可用的指令

主題開發人員可使用的 PHP 指令非常直覺易懂。

get_category_child() 可回傳當前文章的子類別 ID。

is_parent() 可檢查當前文章是否在母類別中。

get_category_title($id) 可取得 $id 所屬類別的標題。

get_category_parent() 可回傳當前文章的母類別 ID。

外掛標籤

開發者團隊

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

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

原文外掛簡介

This plugin provides functions to retrieve the parent category of any particular post should it be assigned to a sub category of that parent category.
Using this feature, the plugin is also able to modify the WordPress Loop to redirect any category page generation to the parent category. This is especially useful when theme developers want to be able to specify category-x.php templates and have all related posts, be it those assigned to the category or the sub categories use that template for page generation.
So for example the current category structure is as follows.

Main Category (has category-x.php template)

Sub Category 1
Sub Category 2

A post is assigned to “Sub Category 2”.
When the post is requested the plugin will automatically detect if it has a parent category. If so, it will modify the WP variables to set the current category as the parent category and add a new variable stating the actual category of the post. This affects the WordPress Loop to category-x.php template defined for the parent
Usable Commands for Theme Developers
The PHP commands for theme developers to use are pretty straight forward.
get_category_child() returns the current post child category ID.
is_parent() checks if the current post is at the parent category.
get_category_title($id) gets the title of the category that is $id.
get_category_parent() returns the current post’s parent category ID.

延伸相關外掛

文章
Filter
Apply Filters
Mastodon