修改 WordPress 內建 widgets 的分類排序

0 Shares
0
0
0

昀芽同學留言詢問說文章分類要如何排序呢?內建的 widgets (模組) 裡,只有三種可以勾選。下拉式選單、顯示文章數量及目錄層次三個功能。

wp_category.png

如果要按照其他的排序方法要怎麼修改?通常不外乎是透過 plugin (插件)來修改,不然就得手動修改,那要怎麼手動修改? 方法不會太難。

步驟

打開 wp-includes 這個目裡,找到 widgets.php 這個檔案, 如果沒有修改過任何的內容,可以找到第 627 行,內容如下:

$cat_args = “orderby=name&show_count={$c}&hierarchical={$h}”;

這邊會發現 orderby=name 就是按照名稱來排序,因為 WordPress 是把 orderby=name 設為 default 。

依照 WordPress 官方網站所提供的資料關於 <font color="#000000"><font color="#0000bb">wp_list_categories <font color="#000000">的用法</font>
</font></font>

orderby
(string) Sort categories alphabetically, by unique Category ID, or by the count of posts in that Category. The default is sort by category name. Valid values: * ID
* name - default
* count

所以可以選擇 分類 ID 排序名稱排序文章數量多寡排序,依照這個就可以修改成自己需要的模式囉。當然也可以修改多到少或者少到多的排序方法,再多一個 order=ASC 或者 order=DESC (ASC 少到多、DESC 多到少)
$cat_args = “order=ASC&orderby=name&show_count={$c}&hierarchical={$h}”;
0 Shares
3 comments

發表迴響

You May Also Like