內容簡介
許多人在部落格上使用 WordPress,且許多網站上有不止一位作者。令人驚訝的是,WordPress 沒有直接支援每位作者個別的分類目錄。
我在網上為了個人需要尋找這個功能,但在任何外掛中都找不到它。確切地說,我使用了一個修改版的另一個類似的外掛,但在 WordPress 的版本 2.3 中,資料庫結構改變後,它就停止運作了。
在我看來,修復舊的、不推薦使用的(並且非常雜亂)代碼並不值得,而且沒有其他解決方案,所以我決定創建一個新的外掛程式。幸運的是,新的資料庫和 API 讓它如我所愿的那麼容易。
最終我使用這個外掛程式,它是作為預設分類目錄的包裝器而創建的。
它很輕量且易於插入和拔除。此外,作為預設分類目錄的擴展,意味著所有功能(排序、帖子計數等)都不會丟失。事實上,它可以輕鬆擴展,而且可以支持未來幾年的部落格平台版本。
用法很簡單,只需在管理面板中上傳和啟用外掛程式,然後調用自定義函數 wp_author_categories(),它會為您創建作者的選單。注意,這僅在作者頁面上有效,在其他情況下會恢復為預設分類目錄。
如果您使用預設模板,您可以輕鬆地在「sidebar.php」中找到顯示分類目錄的這一行:
< ?php wp_list_categories('show_count=1&title_li=Categories’); ?>
您可以將其替換為此條件,當您訪問作者頁面時將使用 wp_author_categories() 函數代替:
<?php
/*
* 首先,寫下您想用於您的選單的參數,並將其存儲在一個變量中。
* 這些選項對於默認選單 ("wp_list_categories") 和作者選單 ("wp_author_categories") 相同。
* 您可以在此處找到有關您可以使用哪些選項的更多信息:https://codex.wordpress.org/Template_Tags/wp_list_categories。
*/
$args = 'show_count=1&title_li=<h2>Categories</h2>';
if($author){
wp_author_categories($args);
} else{
wp_list_categories($args);
}
?>
此外,如果您的模板文件夾中已經有一個「author.php」文件,您可以將「wp_list_categories()」簡單地重命名為「wp_author_categories()」並傳遞相同的參數。
要卸載,只需逆向操作即可。從您的模板文件中刪除 wp_author_categories() 函數的所有引用,然後通過 WordPress 的管理面板卸載外掛程式。
授權條款基於 GNU 通用公共許可證:
http://www.gnu.org/licenses/gpl-2.0.txt
外掛標籤
開發者團隊
原文外掛簡介
Numerous people are using WordPress for blogging and in many cases there are more than one authors on a website. It’s uncomfortably surprising that WordPress doesn’t support out of the box a category menu for each author separately.
I was looking for this feature online for my personal need but couldn’t find it on any plugin. To be exact I was using a modified version of another similar plugin but that was until version 2.3 where the database structure changed for WordPress and it simply stopped working.
As I saw it, it wasn’t worth fixing old, deprecated (and highly cluttered) code, and there weren’t any other solutions out there, so I decided to create a new plugin. Thankfully the new database and API made it as easy as I had hoped for.
I ended up with this plugin, that was created as a wrapper of the default category menu.
It is lightweight and can easily plug-in, plug-out. Furthermore, being an extension of the default category menu, means that none of the functionality (sorting, post count etc.) is lost. In fact it can be easily extended and could support future versions of the blogging platform for years to come.
Usage
After you upload an activate the plugin through your admin panel, all you need to do is call the custom function wp_author_categories() that will create an author’s menu for you. Notice that this only works in author pages and will revert to the default category menu in any other case.
If you are using the default template, you can easily find this line in “sidebar.php” (that displays the category menu):
< ?php wp_list_categories('show_count=1&title_li=Categories’); ?>
You can replace it with this condition that will use the wp_author_categories() function instead, when you are visiting the author pages
Categories
';
if($author){
wp_author_categories($args);
} else{
wp_list_categories($args);
}
?>
Alternatively, and if you already have an “author.php” file in your template folder, you can simply rename “wp_list_categories()” to “wp_author_categories()”, passing the same arguments.
To uninstall, it’s as easy as doing the reverse actions. Delete all references of the wp_author_categories() function from your template files and uninstall the plugin through that WordPress’s admin panel.
License
This work is released under the terms of the GNU General Public License:
http://www.gnu.org/licenses/gpl-2.0.txt
