對于一些多用戶發布文章的文章,如何對這些作者進行有價值的管理是一個問題,
如果wordpress站長需要了解用戶所發布的文章數量,雖然 WordPress 后臺的用戶列表有“文章”這個列,但是默認是不支持排序的,無法快速查看發布了文章的用戶以及他們的文章數量,這一篇的wordpress教程就能很好的解決這個問題。
- 代碼來源:Github
將下面的代碼添加到主題根目錄下的 functions.php文件的<?php
下并保存 即可:
//文章數排序
/*
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();
}
然后,你點擊“文章”這個標題,就可以進行排序啦:
