简体   繁体   English

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

[英]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 此处的get_post()参数的完整参考: http : //codex.wordpress.org/Template_Tags/get_posts

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

相关问题 按字母顺序显示姓名和姓氏列表 - Display Alphabetical order a list of name and surname 如何以字母顺序列出带有标题的项目,如果找不到匹配项,则显示一条消息 - How to list items in alphabetical order with a heading and if no match is found display a message 使用WP类别帖子列表小部件动态显示特定类别(WP / PHP) - Using WP Category Posts List Widget To Dynamically Display Specific Category (WP/PHP) Magento按字母顺序输出类别和子类别 - Magento output category and subcategories in alphabetical order PHP代码显示WP作者并且未登录用户 - PHP code to display WP author and not logged in user WP 如何在一个类别的管理面板中显示一个包含该类别所有已分配帖子列表的字段? - WP How to display a field with a list of all assigned posts of this category in the admin panel of a category? 如何使用Angular.js和PHP根据字母顺序显示列表 - How to display list according to alphabetical order using Angular.js and PHP 自定义输出 wp 列表类别 - Custom output wp list category Magento:按字母顺序对产品显示图像进行排序 - Magento: Sort product display images in alphabetical order 如何使用Magento按字母顺序显示特定类别的所有子类别 - How to show all subcategories of a particular category in alphabetical order with Magento
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM