2012-07-30 79 views
0

默认wp_list_authors将在下面的格式返回作者名单:
<a href="#">AuthorName</a> (PostCount)WordPress的自定义foreach循环波谷错误

我想显示在下面的格式发帖量创作者名单:
<a href="#">AuthorName (PostCount)</a>

以下作者custom foreach loop出现错误(Invalid argument supplied)。
任何suggestiosn我做错了什么?

<?php 
    $args = array(
     'orderby'  => 'post_count', 
     'order'   => 'DESC', 
     'optioncount' => true, 
     'exclude_admin' => false, 
     'show_fullname' => true, 
     'hide_empty' => false, 
     'echo'   => false, 
     'style'   => none, 
     'html'   => false); 

    $author = wp_list_authors($args); 
     foreach($author as $author->ID) { 
     echo '<li><a href="'.get_the_author_link($author->name).'">'.get_the_author().' ('.count_user_posts($author->ID).')</a></li> '; 
    } 

?> 
+0

你得到这个错误的原因是因为该函数没有返回一个数组,它只返回一个以逗号分隔的作者全名字符串。看到我的答案在下面为了得到你想要的。 – stealthyninja 2012-08-31 14:58:38

回答

3

你实际上重做什么wp_list_authors功能已经可以做到。您可以删除整个foreach,只需使用下面的代码来实现你想要的:

$args = array(
    'orderby'  => 'post_count', 
    'order'   => 'DESC', 
    'optioncount' => true, 
    'exclude_admin' => false, 
    'show_fullname' => true, 
    'hide_empty' => false 
); 

$authors = wp_list_authors($args); 

使用此正是您想要显示的列表中,因为它会在那里显示。

+0

如果我想在'