WordPress的author.php是作者页面的模板,如何统计作者的文章数量和评论数量呢?需要用到两个核心的函数:get_comments
、count_user_posts
。
echo '文章数量' . count_user_posts(get_the_author_meta('ID')) . '篇'; $author_ID = get_queried_object()->ID; $args = array( 'user_id' => $author_ID, // use user_id 'count' => true //return only the count ); $comments = get_comments($args); echo '评论数量' . $comments. '条';