操作方法:通过使用 WP_Query() 函数来实现,用循环获取数量。
把下面函数代码添加到当前主题的functions.php文件:
| 代码如下 |
复制代码 |
|
/* number of author's posts by zwwooooo */
function num_of_author_posts($authorID=''){ //根据作者ID获取该作者的文章数量
if ($authorID) {
$author_query = new WP_Query( 'posts_per_page=-1&author='.$authorID );
$i=0;
while ($author_query->have_posts()) : $author_query->the_post(); ++$i; endwhile; wp_reset_postdata();
return $i;
}
return false;
}
|
在要显示作者文章数量的地方添加调用代码:
说明:$authorID 获取方法就很多了,各个页面获取方式不同,自行研究,一般就这几个函数 get_the_author_meta(), get_userdata() … 具体去 WordPress 官方查看(直接在 Google 搜函数名就行了)
另讲一个wordpress注册用户的数量
| 代码如下 |
复制代码 |
|
global $wpdb
$users = $wpdb->get_var("select count(id) from $wpdb->users");
echo "总共有 ".$users." 位注册用户";
|