Dragon主题购买

分享几个实用的站点统计功能代码,可以用来统计网站的基本信息,包括网站文章数、评论数、建站天数等等,可以在页脚或侧边栏或其它任何地方显示一个站点统计的小功能,需要的朋友就自己添加吧。下面只给出对应的统计函数,最终的样式就要靠大家自己折腾了。

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

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

4、建站天数:

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

记得修改 2012-11-22 为你的建站日期

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

<?php $total_users = count_users();echo $total_users['total_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; ?>

根据自己的需要,折腾去吧。

「点点赞赏,手留余香」

还没有人赞赏,快来当第一个赞赏的人吧!

声明:本文转载自Wordpress大学,本文观点不代表龙笑天下立场,版权归原作者所有,欢迎分享本文,转载请保留出处!

2016-05-10

2016-05-12

发表评论

表情 格式 贴图 链接 私密 签到
Dragon主题购买阿里云特价云服务器1核2G低至86元,N4共享型服务器3年仅需799元腾讯云特价云服务器1核2G 88元/年 2核4G3M688元/3年,更有千元代金券礼包免费领!
评论
正在努力加载中...
扫一扫二维码分享
×
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies. Learn more