簡體   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