繁体   English   中英

按字母顺序显示类别的WP作者列表

[英]Display WP Author List for a category in Alphabetical Order

我想在特定类别的名称旁边显示作者姓名和帖子数。 所以才用

<?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>';
}
}
?>

看起来还可以,但是所有作者列表都以错误的排序方式显示。 有最高的帖子作者姓名显示在前, 但我想在该类别的字母顺序中显示作者姓名

因此,请提出一种更改该代码的方法或为我提供另一种方法。

提前致谢

这会给您一些指导吗?

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

此处的get_post()参数的完整参考: http : //codex.wordpress.org/Template_Tags/get_posts

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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