author页面统计作者的文章数量与评论数量

WordPress的author.php是作者页面的模板,如何统计作者的文章数量和评论数量呢?需要用到两个核心的函数:get_commentscount_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. '条';

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注