Emlog博客统计信息添加方法详解
Posted pzg123
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Emlog博客统计信息添加方法详解相关的知识,希望对你有一定的参考价值。
博客统计信息的查询有很多方法,大部分使用的是利用核心文件里面的缓存函数,还可以使用数据库查询的方法。
首先是常用速度比较快的缓存函数方法,大家可以用编辑器打开模板的 module.php 文件,在末尾加上代码:
- <?php
- // 缓存函数统计博客信息
- function ja_sta(){
- global $CACHE;
- $JA_STA = $CACHE->readCache(‘sta‘);
- $JA_STA[‘linknum‘] = count($CACHE->readCache(‘link‘));
- $JA_STA[‘sortnum‘] = count($CACHE->readCache(‘sort‘));
- $JA_STA[‘tagsnum‘] = count($CACHE->readCache(‘tags‘));
- $JA_STA[‘usernum‘] = count($CACHE->readCache(‘user‘));
- extract($JA_STA);
- echo "
- <li>游客可见文章数:$lognum 篇</li>
- <li>隐藏草稿:$draftnum 篇</li>
- <li>未审核的文章数量: $checknum 篇
- <li>未隐藏的评论数:$comnum 条</li>
- <li>被隐藏的评论数:$hidecomnum 条</li>
- <li>所有评论数:$comnum_all 条</li>
- <li>微语:$twnum 条</li>
- <li>友链:$linknum 个</li>
- <li>分类:$sortnum 个</li>
- <li>标签:$tagsnum 个</li>
- <li>作者:$usernum 人</li>
- ";
- }
- ?>
然后在模板的 footer.php 文件或者 side.php 文件合适的位置添加使用代码:
- <?php ja_sta(); ?>
另外一种方法是使用数据库查询的方法,这种方法比较准确但是加载慢一点~
同样在模板的 module.php 文件添加代码:
- <?php
- //统计文章总数
- function count_log_all(){
- $db = mysql::getInstance();
- $data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "blog WHERE type = ‘blog‘");
- return $data[‘total‘];
- }
- //置顶文章数
- function count_log_top(){
- $db = MySql::getInstance();
- $data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "blog WHERE top = ‘y‘ or sortop = ‘y‘ AND type = ‘blog‘");
- return $data[‘total‘];
- }
- //隐藏文章数
- function count_log_hide(){
- $db = MySql::getInstance();
- $data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "blog WHERE hide = ‘y‘ AND type = ‘blog‘");
- return $data[‘total‘];
- }
- //未审核文章数
- function count_log_check(){
- $db = MySql::getInstance();
- $data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "blog WHERE checked = ‘n‘ AND type = ‘blog‘");
- return $data[‘total‘];
- }
- //加密文章数
- function count_log_pass(){
- $db = MySql::getInstance();
- $data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "blog WHERE password !=‘‘ AND type = ‘blog‘");
- return $data[‘total‘];
- }
- //统计页面总数
- function count_page_all(){
- $db = MySql::getInstance();
- $data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "blog WHERE type = ‘page‘");
- return $data[‘total‘];
- }
- //统计评论总数
- function count_com_all(){
- $db = MySql::getInstance();
- $data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "comment");
- return $data[‘total‘];
- }
- //统计友链总数
- function count_link_all(){
- $db = MySql::getInstance();
- $data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "link");
- return $data[‘total‘];
- }
- //统计微语评论总数
- function count_treply_all(){
- $db = MySql::getInstance();
- $data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "reply");
- return $data[‘total‘];
- }
- //统计分类总数
- function count_sort_all(){
- $db = MySql::getInstance();
- $data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "sort");
- return $data[‘total‘];
- }
- //统计子分类数
- function count_sort_mod(){
- $db = MySql::getInstance();
- $data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "sort WHERE pid != 0");
- return $data[‘total‘];
- }
- //统计标签总数
- function count_tag_all(){
- $db = MySql::getInstance();
- $data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "tag");
- return $data[‘total‘];
- }
- //统计微语总数
- function count_tw_all(){
- $db = MySql::getInstance();
- $data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "twitter");
- return $data[‘total‘];
- }
- //统计用户总数
- function count_user_all(){
- $db = MySql::getInstance();
- $data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "user");
- return $data[‘total‘];
- }
- //统计管理员总数
- function count_user_admin(){
- $db = MySql::getInstance();
- $data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "user WHERE role = ‘admin‘");
- return $data[‘total‘];
- }
- //统计作者总数
- function count_user_writer(){
- $db = MySql::getInstance();
- $data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "user WHERE role = ‘writer‘");
- return $data[‘total‘];
- }
- //统计附件总数
- function count_att_all(){
- $db = MySql::getInstance();
- $data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "attachment");
- return $data[‘total‘];
- }
- //最后发表文章时间
- function last_post_log(){
- $db = MySql::getInstance();
- $sql = "SELECT * FROM " . DB_PREFIX . "blog WHERE type=‘blog‘ ORDER BY date DESC LIMIT 0,1";
- $res = $db->query($sql);
- $row = $db->fetch_array($res);
- $date = date(‘Y-n-j H:i‘,$row[‘date‘]);
- return $date;
- };
- // 输出函数
- function echo_count_info(){
- echo "
- <li>文章总数:<?php echo count_log_all(); ?></li>
- <li>置顶文章数:<?php echo count_log_top(); ?></li>
- <li>隐藏文章数:<?php echo count_log_hide(); ?></li>
- <li>未审核文章数:<?php echo count_log_check(); ?></li>
- <li>加密文章数:<?php echo count_log_pass(); ?></li>
- <li>页面总数:<?php echo count_page_all(); ?></li>
- <li>评论总数:<?php echo count_com_all(); ?></li>
- <li>微语评论总数:<?php echo count_sort_all(); ?></li>
- <li>分类总数:<?php echo count_log_all(); ?></li>
- <li>子分类数:<?php echo count_sort_mod(); ?></li>
- <li>标签总数:<?php echo count_tag_all(); ?></li>
- <li>微语总数:<?php echo count_tw_all(); ?></li>
- <li>标签总数:<?php echo count_tag_all(); ?></li>
- <li>用户总数:<?php echo count_user_all(); ?></li>
- <li>管理员总数:<?php echo count_user_admin(); ?></li>
- <li>作者总数:<?php echo count_user_writer(); ?></li>
- <li>附件总数:<?php echo count_att_all(); ?></li>
- <li>最后发表文章时间:<?php echo last_post_log(); ?></li>
- ";
- }
- ?>
然后在模板的 footer.php或者side.php 文件添加代码:
- <?php echo_count_info(); ?>
大家可以根据自己需要改变文字和格式,也可以单个使用哦,如文章总数可单独使用 <?php echo count_log_all(); ?> 得到~
以上是关于Emlog博客统计信息添加方法详解的主要内容,如果未能解决你的问题,请参考以下文章