首页 / WordPress建站 / 基础教程 / WordPress站点统计功能代码(文章数/建站天数等)
Loading收藏2

最近有同学询问倡萌,如何实现网站的基本信息统计功能,包括网站文章数、评论数、建站天数等等。在万戈博客找到了对应的WordPress站点统计功能代码,需要的朋友就自己添加吧。下面只给出对应的统计函数,最终的样式就要靠大家自己折腾了。

1、日志总数:

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

2、草稿数目:

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

3、评论总数:

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

4、建站天数:

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

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

5、标签总数:

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

6、页面总数:

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

7、分类总数:

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

8、链接总数:

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

9、用户总数:

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

10、最后更新:

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

根据自己的需要使用吧。

你可能还喜欢

15 条评论

    1. <span id="timeDate">载入天数…</span><span id="times">载入时分秒…</span> <script language="javascript">
      var now = new Date();
      function createtime(){
      var grt= new Date("02/07/2014 21:51: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>

发表评论

我们是靠谱的WordPress建站团队!

专业承接WordPress网站建设及运维、WordPress主题和插件开发、汉化、安装等服务

联系电话:0773-8282430

查看所有服务项目

视频教程: 点击联系我们
定制开发: 点击联系我们
售后支持: 点击联系我们
商务合作: 点击联系我们

固话:0773-8282-430

手机:133-0773-9152

微信扫一扫,联系我们