WordPress 讓後臺用戶列表可以根據文章數進行排序

對於開放註冊的 WordPress 多用戶部落格而言,我們可能需要瞭解用戶所發佈的文章數量,雖然 WordPress 後臺的用戶列表有“文章”這個列,但是默認是不支援排序的,無法快速查看發佈瞭文章的用戶以及他們的文章數量,要解決這個問題,我們隻需要將下面的代碼添加到主題的 functions.php 即可:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
Plugin Name: Sort Users by Post Count
Description: Add a column to the Users page in the admin to sort users by post counts.https://github.com/ksemel/sort-users-by-post-count
Version: 1.0
Author: Katherine Semel
*/
if ( ! class_exists('Sort_Users_By_Post_Count') ) {
    class Sort_Users_By_Post_Count {
        function Sort_Users_By_Post_Count() {
            // Make user table sortable by post count
            add_filter( 'manage_users_sortable_columns', array( $this, 'add_custom_user_sorts' ) );
        }
        /* Add sorting by post count to user page */
        function add_custom_user_sorts( $columns ) {
            $columns['posts'] = 'post_count';
            return $columns;
        }
    }
    $Sort_Users_By_Post_Count = new Sort_Users_By_Post_Count();
}

/*
Plugin Name: Sort Users by Post Count
Description: Add a column to the Users page in the admin to sort users by post counts.https://github.com/ksemel/sort-users-by-post-count
Version: 1.0
Author: Katherine Semel
*/
if ( ! class_exists(‘Sort_Users_By_Post_Count’) ) {
class Sort_Users_By_Post_Count {
function Sort_Users_By_Post_Count() {
// Make user table sortable by post count
add_filter( ‘manage_users_sortable_columns’, array( $this, ‘add_custom_user_sorts’ ) );
}
/* Add sorting by post count to user page */
function add_custom_user_sorts( $columns ) {
$columns[‘posts’] = ‘post_count’;
return $columns;
}
}
$Sort_Users_By_Post_Count = new Sort_Users_By_Post_Count();
}

然後,你點擊“文章”這個標題,就可以進行排序啦:

2015-08-27_102837_wpdaxue_com

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *