我的 Wordpress 博客中有一个作者页面,但我也想将每个作者的帖子数量显示为一个数字。我对数据库查询了解不多,所以我想知道如何使用每个用户的帖子数量来扩展以下查询。
到目前为止,这是我的代码:
function contributors() {
global $wpdb;
$authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users WHERE display_name <> 'admin' ORDER BY display_name");
foreach ($authors as $author ) {
echo "<li>";
echo "<div class='author-image'>";
echo "<a href=\"".get_bloginfo('url')."/?author=";
echo $author->ID;
echo "\">";
echo userphoto($author->ID);
echo "</a>";
echo "</div>";
echo "<div class='meta'>";
echo "<h2 class='author-name'>";
the_author_meta('display_name', $author->ID);
echo "</h2>";
echo "<span class='count'>";
count_user_posts($author->ID); //Not working
echo " Articles</span>";
echo "<p class='description'>";
the_author_meta('description', $author->ID);
echo "</p>";
echo "<span class='top-dotted'></span>";
echo "</div>";
echo "</li>";
}
}