回答您的问题:
按帖子数量排序您可以将所需的所有信息收集到一个数组中,并按帖子数量对该数组进行排序,如下所示:
//function to sort array by filed
function authors_orderBy($data, $field){
$code = "if (\\$a[\'$field\'] == \\$b[\'$field\']) {return 0;} return (\\$a[\'$field\'] < \\$b[\'$field\']) ? 1 : -1;";
usort($data, create_function(\'$a,$b\', $code));
return $data;
}
然后更改代码,如下所示:
$blogusers = get_users_of_blog();
if ($blogusers) {
$au = array();
foreach ($blogusers as $bloguser) {
$user = get_userdata($bloguser->user_id);
$post_count = count_user_posts($user->ID);
$au[] = array(\'user_id\' => $user->ID , \'nicename\' => $user->user_nicename, \'display_name\' => $user->display_name, \'email\' => $user->user_email ,\'post_count\' => $post_count);
}
//Sort array
$au = authors_orderBy($au, \'post_count\');
//then loop through the authors
foreach ($au as $aut){
if ($aut[\'post_count\'] > 0) {
echo \'<li>\';
echo \'<a href="\'.get_bloginfo(\'url\').\'/author/\' . $aut[\'nicename\'] . \'">\'.get_avatar($aut[\'email\'], \'36\').\'</a>\';
echo \'<a href="\'.get_bloginfo(\'url\').\'/author/\' . $aut[\'nicename\'] . \'">\'.$aut[\'display_name\'] .\' (\'.$aut[\'post_count\'].\')</a><li>\';
}
}
}
get\\u users\\u of\\u blog是一个贬值的博客,这很奇怪,因为看看法典是的,这个功能是贬值的,你应该使用
get_users()
应随版本3.1一起提供
/**
* Retrieve list of users matching criteria.
*
* @since 3.1.0
* @uses $wpdb
* @uses WP_User_Query See for default arguments and information.
*
* @param array $args
* @return array List of users.
*/
function get_users( $args ) {
$args = wp_parse_args( $args );
$args[\'count_total\'] = false;
$user_search = new WP_User_Query($args);
return (array) $user_search->get_results();
}
但如果您查看wp\\u list\\u authors,它会使用get\\u users\\u of\\u blog()本身。
希望这有帮助。