wordpress获取调用注册会员发表的文章数量
操作方法: 通过使用 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; }在要显示作者文章数量的地方添加调用代码,代码如下:
<?php echo num_of_author_posts($authorID); ?>
说明: $authorID 获取方法就很多了,各个页面获取方式不同,自行研究,一般就这几个函数 get_the_author_meta(),get_userdata() … 具体去 WordPress 官方查看(直接在 Google 搜函数名就行了)
另讲一个wordpress注册用户的数量 ,代码如下:
global $wpdb $users = $wpdb ->get_var( "select count(id) from $wpdb->users" ); echo "总共有 " . $users . " 位注册用户" ;查看更多关于wordpress获取调用注册会员发表的文章数量 - Word的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did8638