0
我在我的WordPress博客中有一個作者頁面,但我也想顯示每個作者的帖子數量作爲數字。我不太瞭解數據庫查詢,所以我想知道如何使用每個用戶的帖子數量來擴展以下查詢。從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>";
}
}
想通了,謝謝! –