- Joined
- Feb 27, 2013
- Messages
- 72
- Points
- 0
I have struggle the whole morning with this code. This is to show authors from a certain category. Feel free to make it work for you, but this works for me....
PHP:
<?php
$catauthors = array();
$citycat=8;
$allposts=get_posts("cat=$citycat&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->user_nicename .'</a></p>';
}
}
?>
Last edited by a moderator: