当前位置:首页 > CMS教程 > WordPress > 列表

wordpress获取调用注册会员发表的文章数量

发布:smiling 来源: PHP粉丝网  添加日期:2014-03-19 13:15:20 浏览: 评论:0 

操作方法:通过使用 WP_Query() 函数来实现,用循环获取数量,把下面函数代码添加到当前主题的functions.php文件,代码如下:

  1. /* number of author's posts by zwwooooo */ 
  2.  function num_of_author_posts($authorID=''){ //根据作者ID获取该作者的文章数量 
  3.      if ($authorID) { 
  4.          $author_query = new WP_Query( 'posts_per_page=-1&author='.$authorID ); 
  5.          $i=0; 
  6.          while ($author_query->have_posts()) : $author_query->the_post(); ++$iendwhile; wp_reset_postdata(); 
  7.          return $i
  8.      } 
  9.      return false; 
  10.  } 

在要显示作者文章数量的地方添加调用代码,代码如下:

<?php echo num_of_author_posts($authorID); ?>

说明:$authorID 获取方法就很多了,各个页面获取方式不同,自行研究,一般就这几个函数 get_the_author_meta(),get_userdata() … 具体去 WordPress 官方查看(直接在 Google 搜函数名就行了)

另讲一个wordpress注册用户的数量,代码如下:

  1. global $wpdb 
  2. $users = $wpdb->get_var("select count(id) from $wpdb->users"); 
  3. echo "总共有 ".$users." 位注册用户"

Tags: wordpress 注册会员 文章数量

分享到: