WordPress函数:get_the_author_posts 获取当前作者的文章数量

江河/ 2023年05月02日/ WordPress/ 浏览 483

函数原型:


get_the_author_posts(): int


获取当前作者文章的数量。


这个函数的名字比较令人迷惑,实际上这个函数只返回作者的文章数量,而不是作者的文章列表。


函数源码:


function get_the_author_posts() {
	$post = get_post();
	if ( ! $post ) {
		return 0;
	}
	return count_user_posts( $post->post_author, $post->post_type );
}


使用举例:


<p><?php the_author(); ?> 发布了 <?php echo number_format_i18n( get_the_author_posts() ); ?> 篇文章</p>


结果:某某发布了N篇文章。

发表评论

暂无评论,抢个沙发...

客服 工单