前言:在我们使用wordpress建站的时候总会使用一wordpress自带的统计代码来精简代码达到优化页面和减少对数据库的请求。

这里我给大家总结了一些常用的统计代码,希望能够帮到大家。

//WordPress建站运行天数:(记得修改为你的建站日期)

<?php echo floor((time()-strtotime(“2012-11-22”))/86400); ?>

//WordPress标签总数统计代码:

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

//WordPress页面总数统计代码:

<?php $count_pages = wp_count_posts(‘page’); echo $page_posts = $count_pages->publish; ?>

//WordPress分类总数统计代码:

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

//WordPress用户总数统计代码:

<?php $users = $wpdb->get_var(“SELECT COUNT(ID) FROM $wpdb->users”); echo $users; ?>

//WordPress最后更新日期:

<?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; ?>

//WordPress日志总数统计代码:

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

//WordPress草稿数目统计代码:

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

//WordPress评论总数统计代码:

<?php echo $wpdb->get_var(“SELECT COUNT(*) FROM $wpdb->comments”);?>

//WordPress链接总数统计代码:

<?php $link = $wpdb->get_var(“SELECT COUNT(*) FROM $wpdb->links WHERE link_visible = ‘Y'”); echo $link; ?>

发表评论

电子邮件地址不会被公开。 必填项已用*标注