网站技术

WordPress站点统计功能代码(文章数/建站天数等)

2017/04/07 20,739 暂无评论 GoaKay小狼

在制作wordpress主题期间,有的时候会用到【已经运行了2天,共发表了12篇原创文章,共收到了5 条有效评论】等wordpress站点信息,如何实现网站的基本信息统计功能,包括网站文章数、评论数、建站天数等等。下面只给出对应的统计函数,最终的样式就要靠大家自己折腾了。

1.日志总数:

<?php $count_posts = wp_count_posts(); echo $published_posts = $count_posts->gt;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 $count_tags = wp_count_terms('post_tag'); ?>

5.页面总数:

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

6.分类总数:

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

7.链接总数:

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

8.用户总数:

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

9.最后更新:

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

10.建站天数:

<?php echo floor((time()-strtotime("2012-11-22"))/86400); ?>
记得修改 2012-11-22 为你的建站日期

11.建站天数(精确到秒,可以在网页上看着它一秒一秒的动):

<script language="javascript">var now = new Date();function createtime(){
var grt= new Date("04/07/2017 00:00:00");//此处修改你的建站时间或者网站上线时间
now.setTime(now.getTime()+250);
days = (now - grt ) / 1000 / 60 / 60 / 24;
dnum = Math.floor(days);
hours = (now - grt ) / 1000 / 60 / 60 - (24 * dnum);
hnum = Math.floor(hours);
if(String(hnum).length ==1 ){hnum = "0" + hnum;}
minutes = (now - grt ) / 1000 /60 - (24 * 60 * dnum) - (60 * hnum);
mnum = Math.floor(minutes);
if(String(mnum).length ==1 ){mnum = "0" + mnum;}
seconds = (now - grt ) / 1000 - (24 * 60 * 60 * dnum) - (60 * 60 * hnum) - (60 * mnum);
snum = Math.round(seconds);
if(String(snum).length ==1 ){snum = "0" + snum;}
document.getElementById("timeDate").innerHTML = "本站已运行"+dnum+"天";
document.getElementById("times").innerHTML = hnum + "小时" + mnum + "分" + snum + "秒";
}
setInterval("createtime()",250);
</script>
订阅
提醒
guest

0 评论
Inline Feedbacks
View all comments