Emlog博客统计信息添加方法详解

Posted pzg123

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Emlog博客统计信息添加方法详解相关的知识,希望对你有一定的参考价值。

博客统计信息的查询有很多方法,大部分使用的是利用核心文件里面的缓存函数,还可以使用数据库查询的方法。              

首先是常用速度比较快的缓存函数方法,大家可以用编辑器打开模板的 module.php 文件,在末尾加上代码:

  1. <?php
  2. // 缓存函数统计博客信息
  3. function ja_sta(){
  4. global $CACHE;
  5. $JA_STA = $CACHE->readCache(‘sta‘);
  6. $JA_STA[‘linknum‘] = count($CACHE->readCache(‘link‘));
  7. $JA_STA[‘sortnum‘] = count($CACHE->readCache(‘sort‘));
  8. $JA_STA[‘tagsnum‘] = count($CACHE->readCache(‘tags‘));
  9. $JA_STA[‘usernum‘] = count($CACHE->readCache(‘user‘));
  10. extract($JA_STA);
  11. echo "
  12. <li>游客可见文章数:$lognum 篇</li>
  13. <li>隐藏草稿:$draftnum 篇</li>
  14. <li>未审核的文章数量: $checknum 篇
  15. <li>未隐藏的评论数:$comnum 条</li>
  16. <li>被隐藏的评论数:$hidecomnum 条</li>
  17. <li>所有评论数:$comnum_all 条</li>
  18. <li>微语:$twnum 条</li>
  19. <li>友链:$linknum 个</li>
  20. <li>分类:$sortnum 个</li>
  21. <li>标签:$tagsnum 个</li>
  22. <li>作者:$usernum 人</li>
  23. ";
  24. }
  25. ?>

然后在模板的 footer.php 文件或者 side.php 文件合适的位置添加使用代码:

  1. <?php ja_sta(); ?>

另外一种方法是使用数据库查询的方法,这种方法比较准确但是加载慢一点~

同样在模板的 module.php 文件添加代码:

  1. <?php
  2. //统计文章总数
  3. function count_log_all(){
  4. $db = mysql::getInstance();
  5. $data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "blog WHERE type = ‘blog‘");
  6. return $data[‘total‘];
  7. }
  8. //置顶文章数
  9. function count_log_top(){
  10. $db = MySql::getInstance();
  11. $data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "blog WHERE top = ‘y‘ or sortop = ‘y‘ AND type = ‘blog‘");
  12. return $data[‘total‘];
  13. }
  14. //隐藏文章数
  15. function count_log_hide(){
  16. $db = MySql::getInstance();
  17. $data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "blog WHERE hide = ‘y‘ AND type = ‘blog‘");
  18. return $data[‘total‘];
  19. }
  20. //未审核文章数
  21. function count_log_check(){
  22. $db = MySql::getInstance();
  23. $data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "blog WHERE checked = ‘n‘ AND type = ‘blog‘");
  24. return $data[‘total‘];
  25. }
  26. //加密文章数
  27. function count_log_pass(){
  28. $db = MySql::getInstance();
  29. $data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "blog WHERE password !=‘‘ AND type = ‘blog‘");
  30. return $data[‘total‘];
  31. }
  32. //统计页面总数
  33. function count_page_all(){
  34. $db = MySql::getInstance();
  35. $data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "blog WHERE type = ‘page‘");
  36. return $data[‘total‘];
  37. }
  38. //统计评论总数
  39. function count_com_all(){
  40. $db = MySql::getInstance();
  41. $data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "comment");
  42. return $data[‘total‘];
  43. }
  44. //统计友链总数
  45. function count_link_all(){
  46. $db = MySql::getInstance();
  47. $data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "link");
  48. return $data[‘total‘];
  49. }
  50. //统计微语评论总数
  51. function count_treply_all(){
  52. $db = MySql::getInstance();
  53. $data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "reply");
  54. return $data[‘total‘];
  55. }
  56. //统计分类总数
  57. function count_sort_all(){
  58. $db = MySql::getInstance();
  59. $data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "sort");
  60. return $data[‘total‘];
  61. }
  62. //统计子分类数
  63. function count_sort_mod(){
  64. $db = MySql::getInstance();
  65. $data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "sort WHERE pid != 0");
  66. return $data[‘total‘];
  67. }
  68. //统计标签总数
  69. function count_tag_all(){
  70. $db = MySql::getInstance();
  71. $data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "tag");
  72. return $data[‘total‘];
  73. }
  74. //统计微语总数
  75. function count_tw_all(){
  76. $db = MySql::getInstance();
  77. $data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "twitter");
  78. return $data[‘total‘];
  79. }
  80. //统计用户总数
  81. function count_user_all(){
  82. $db = MySql::getInstance();
  83. $data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "user");
  84. return $data[‘total‘];
  85. }
  86. //统计管理员总数
  87. function count_user_admin(){
  88. $db = MySql::getInstance();
  89. $data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "user WHERE role = ‘admin‘");
  90. return $data[‘total‘];
  91. }
  92. //统计作者总数
  93. function count_user_writer(){
  94. $db = MySql::getInstance();
  95. $data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "user WHERE role = ‘writer‘");
  96. return $data[‘total‘];
  97. }
  98. //统计附件总数
  99. function count_att_all(){
  100. $db = MySql::getInstance();
  101. $data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "attachment");
  102. return $data[‘total‘];
  103. }
  104. //最后发表文章时间
  105. function last_post_log(){
  106. $db = MySql::getInstance();
  107. $sql = "SELECT * FROM " . DB_PREFIX . "blog WHERE type=‘blog‘ ORDER BY date DESC LIMIT 0,1";
  108. $res = $db->query($sql);
  109. $row = $db->fetch_array($res);
  110. $date = date(‘Y-n-j H:i‘,$row[‘date‘]);
  111. return $date;
  112. };
  113. // 输出函数
  114. function echo_count_info(){
  115. echo "
  116. <li>文章总数:<?php echo count_log_all(); ?></li>
  117. <li>置顶文章数:<?php echo count_log_top(); ?></li>
  118. <li>隐藏文章数:<?php echo count_log_hide(); ?></li>
  119. <li>未审核文章数:<?php echo count_log_check(); ?></li>
  120. <li>加密文章数:<?php echo count_log_pass(); ?></li>
  121. <li>页面总数:<?php echo count_page_all(); ?></li>
  122. <li>评论总数:<?php echo count_com_all(); ?></li>
  123. <li>微语评论总数:<?php echo count_sort_all(); ?></li>
  124. <li>分类总数:<?php echo count_log_all(); ?></li>
  125. <li>子分类数:<?php echo count_sort_mod(); ?></li>
  126. <li>标签总数:<?php echo count_tag_all(); ?></li>
  127. <li>微语总数:<?php echo count_tw_all(); ?></li>
  128. <li>标签总数:<?php echo count_tag_all(); ?></li>
  129. <li>用户总数:<?php echo count_user_all(); ?></li>
  130. <li>管理员总数:<?php echo count_user_admin(); ?></li>
  131. <li>作者总数:<?php echo count_user_writer(); ?></li>
  132. <li>附件总数:<?php echo count_att_all(); ?></li>
  133. <li>最后发表文章时间:<?php echo last_post_log(); ?></li>
  134. ";
  135. }
  136. ?>

然后在模板的 footer.php或者side.php 文件添加代码:

  1. <?php echo_count_info(); ?>

大家可以根据自己需要改变文字和格式,也可以单个使用哦,如文章总数可单独使用 <?php echo count_log_all(); ?> 得到~

以上是关于Emlog博客统计信息添加方法详解的主要内容,如果未能解决你的问题,请参考以下文章

mysql-5.7 持久化统计信息详解

MySQLMySQL 5.7持久化统计信息详解

Linux Sar命令详解

如何为你的博客园添加到百度统计

为你的CSDN博客添加CNZZ流量统计功能

为你的CSDN博客添加CNZZ流量统计功能