外贸独立站的底层设计密码WordPress 成品站模板
当前位置:首页>WordPress建站>基础教程>WordPress站点统计功能代码(文章数/建站天数等)

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

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

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

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

根据自己的需要使用吧。

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA打赏
共{{data.count}}人
人已打赏
欢迎关注WordPress大学公众号 WPDAXUE
基础教程

WordPress返回顶部插件:wp-auto-top

2012-11-9 6:14:00

基础教程

WordPress高级页面内容过滤插件:Cat-Comment-Filter

2012-11-26 5:53:00

15 条回复 A文章作者 M管理员
  1. 最后更新的功能好像失效了

  2. 请问为什么 链接总数 这个统计代码不能在小工具中正常使用,使用 链接总数 这个统计代码导致侧边拦空白

  3. 有今日更新多少篇文章的代码吗

  4. 超級efly

    也把這個做成插件啦~https://wordpress.org/plugins/site-analytics-widget/

  5. 可以把这个建站天数精确到秒,然后可以在网页上看着它一秒一秒的动吗?

    • <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>

    • 无以回报,来增加访问量了

  6. 白白

    請問這個加在小工具可以嗎?我嘗試了一下,并沒有起作用。

    • 倡萌

      小工具默认是不能添加php代码的

  7. 如果有访问量总数统计就好了。

    • 有的,http://www.chunfengxiyu.com/wordpress-blog-statistics-widget.html

  8. 来访人数如何判断?

  9. 最后更新代码是统计更新文章的么?我这边最后一篇文章是21日,但是它显示的是23日.是不是回复别人评论也算是更新呢?

    • 它是根据 post_modified 来划分的,也就是你最后修改文章 或 页面 的时间,不一定是发布的时间

  10. 建站天数我用的js…

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索