统计代码效果图如下:
具体样式,选择展示统计内容可根据自己需求调整。
调用方法:
将自己需要使用的代码放入到对于的模板文件即可。
统计代码如下:
1、日志总数:
<?php $count_posts = wp_count_posts(); echo $published_posts = $count_posts->publish;?>
2、草稿数目:
<?php $count_posts = wp_count_posts(); echo $draft_posts = $count_posts->draft; ?>
3、评论总数:
<?php echo $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments");?>
4、建站天数:
<?php echo floor((time()-strtotime("2020-10-1"))/86400); ?>
2020-10-1 为你的建站日期,数值越小,建站天数时间就越多,所以你在外面看到的网站建站天数都是可以自己随意更改的。
5、标签总数:
<?php echo $count_tags = wp_count_terms('post_tag'); ?>
6、文章页面总数:
<?php $count_pages = wp_count_posts('page'); echo $page_posts = $count_pages->publish; ?>
7、分类总数:
<?php echo $count_categories = wp_count_terms('category'); ?>
8、链接总数:
<?php $link = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->links WHERE link_visible = 'Y'"); echo $link; ?>
9、用户总数:
<?php $users = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users"); echo $users; ?>
10、最后更新:
<?php $last = $wpdb->get_results("SELECT MAX(post_modified) AS MAX_m FROM $wpdb->posts WHERE (post_type = 'post' OR post_type = 'page') AND (post_status = 'publish' OR post_status = 'private')");$last = date('Y-n-j', strtotime($last[0]->MAX_m));echo $last; ?>
11、一周内发布更新的文章内容数量:
1.先将以下函数放入到functions.php文件中
function get_posts_count_from_last_24h($post_type ='post') {
global $wpdb;
$numposts = $wpdb->get_var(
$wpdb->prepare(
"SELECT COUNT(ID) ".
"FROM {$wpdb->posts} ".
"WHERE ".
"post_status='publish' ".
"AND post_type= %s ".
"AND post_date> %s",
$post_type, date('Y-m-d H:i:s', strtotime('-7 hours'))
)
);
return $numposts;
}
2.放入模板文件中的代码如下:
<?php echo get_posts_count_from_last_7h(); ?>
THE END
暂无评论内容