简体   繁体   中英

Display WP Author List for a category in Alphabetical Order

I want to show the author name and post count beside the name for particular category. That's why i used,

<?php
$catauthors = array();
$my_cat_id=4;  // THAT IS MY CATEGORY ID
$allposts=get_posts("cat=$my_cat_id&showposts=-1");
if ($allposts) {
foreach($allposts as $authorpost) {
$catauthors[$authorpost->post_author]+=1;
}
arsort($catauthors); //sort array in reverse order by number of posts
foreach($catauthors as $key => $author_post_count) {
$curuser = get_userdata($key);

$author_post_url=get_author_posts_url($curuser->ID, $curuser->nicename);
echo '<p><a href="' . $author_post_url . '" title="' . sprintf( __( "Posts by %s" ), $curuser->user_nicename ) . '" ' . '>'. $curuser->display_name . '</a> <span class="label label-success">' .$author_post_count .'</span></p>';
}
}
?>

It seems OK but there all the author list showing with wrong sorting way. There highest post author names showing first, BUT i want to show the authors name in Alphabetical ORDER For that Category .

SO please suggest me a way to change that code or give me another way to that.

Thanks in advance

Does this gives you some direction?

$args = array( 'orderby' => 'author', 'order'=> 'ASC', 'category' => 4 );
$myposts = get_posts( $args );

Full reference for get_post() arguments here: http://codex.wordpress.org/Template_Tags/get_posts

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM