WordPress 状态信息统计代码

登陆 WordPress 的后台控制面板,系统会自动显示当前的 WordPress 状态信息概览。包括文章数,页面数,草稿数,分类目录数,标签数,以及评论数等统计信息。如下是芒果总结的一些统计代码,用于单独调用上述信息的数目统计。php

1. 文章数目服务器

<?php $count_posts = wp_count_posts(); echo $published_posts = $count_posts->publish;?>app

若是服务器环境为 PHP5,则代码能够写成以下形式:函数

<?php  echo $published_posts = wp_count_posts()->publish; ?>post

考虑到对 PHP4 的兼容性,你能够选择第一种代码。get

2. 页面数目
和文章数目统计同样,页面数目也使用 wp_count_posts 函数,具体代码为:登录

<?php  $count_pages = wp_count_posts('page'); echo $page_posts = $count_pages->publish;?>后台

3. 草稿数目
和文章数目统计同样,草稿数目也使用 wp_count_posts 函数,具体代码为:兼容性

<?php  $count_posts = wp_count_posts();echo $draft_posts = $count_posts->draft;?>统计

4. 分类目录数目
这里用到了 wp_count_terms 函数,具体代码为:

<?php  echo $count_categories = wp_count_terms('category');?>

5. 标签数目
同分类目录数目统计,标签数目也使用 wp_count_terms 函数,具体代码为:

<?php echo $count_tags = wp_count_terms('post_tag'); ?>

6. 评论数目

<?php$count_comments = get_comment_count(); echo $count_comments['approved'];?>

以上代码显示已获准经过评论数目。