Only show authors with posts

时间:2012-01-11 作者:Josh

我以为下面的代码可以用。。。但没有骰子。类似于“AND post\\u count>0”

函数贡献者(){全局$wpdb;

$authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users WHERE display_name <> \'admin\' AND post_count > 0 ORDER BY display_name");

foreach ($authors as $author ) {

echo "<li>";
echo "<a href=\\"".get_bloginfo(\'url\')."/author/";
the_author_meta(\'user_nicename\', $author->ID);
echo "/\\">";
echo get_avatar($author->ID, 12);
echo "</a>";
echo "<a href=\\"".get_bloginfo(\'url\')."/author/";
the_author_meta(\'user_nicename\', $author->ID);
echo "/\\">";
the_author_meta(\'display_name\', $author->ID);
echo "</a>";
echo "</li>";
}
}

1 个回复
SO网友:mor7ifer

$args = array(
    \'posts_per_page\' => 1,
    \'author\'         => $author->ID
);
$posts = new WP_Query( $args );
$count = count( $posts );
将其放在foreach后面,$count现在将包含1或0,通过if语句过滤输出。

结束

相关推荐