QQ资源吧-免费分享全网优质资源

Emlog实现网站信息统计的代码

QQ资源吧 编程相关
扫码手机访问
0
  前言:

  有时候想在网页中向访客展示Emlog个人博客的文章数量、评论数量、运行时间等信息

  但emlog后台侧边栏没有提供相关的模块,因此需要站长自主添加个人博客统计信息代码

  下面是AIDE技术网整理的Emlog网站信息统计代码,已在emlog 5.3.1+上测试可用,最新版6.0.1也是可以用的

  正文:

  方法一

  利用Emlog官方缓存类统计代码

  优点:加载速度快

  缺点:可能信息更新不及时

  把以下代码添加到当前使用的主题模板文件中,无陌然建议放在侧边栏side.php文件底部

<?php $sta_cache = Cache::getInstance()->readCache('sta'); ?>
<li>日志数量:<?php echo $sta_cache['lognum']; ?></li>
<li>评论数量:<?php echo $sta_cache['comnum']; ?></li>
<li>微语数量:<?php echo $sta_cache['tbnum']; ?></li>
<li>运行时间:<?php echo floor((time()-strtotime("2018-04-04"))/86400); ?>天</li>

  这里解释一下代码:

  $sta_cache[‘参数’]中的参数可选如下

  lognum游客可见日志总数

  comnum未隐藏的评论数量

  tbnum微语数量

  方法二

  自编函数通过SQL语句查询相关数据

  优点:实时显示

  缺点:加载速度较缓存类慢(无陌然技术博客用过该代码,后期直接莫名其妙数据库出错,不太建议使用)

  把下面的代码添加到模版文件下的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;       
};
?>

  然后在需要的地方调用就行,调用代码如下
<ul>
<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_link_all();?></li>
<li>微语评论:<?php echo count_treply_all();?></li>
<li>分类总数:<?php echo count_sort_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_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>
</ul>
  您阅读这篇文章共花了: 

标签:

emlog

免责声明:

本站提供的资源,都来自网络,版权争议与本站无关,所有内容及软件的文章仅限用于学习和研究目的。不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负,我们不保证内容的长久可用性,通过使用本站内容随之而来的风险与本站无关,您必须在下载后的24个小时之内,从您的电脑/手机中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。侵删请致信E-mail: @qq.com

同类推荐
评论列表

相关通知:

如发现本站有侵权违规的相关内容请致信E-mail: @qq.com

富强民主文明和谐自由平等公正法制丨爱国敬业诚信友善
协助本站优化一下
百度一下
关键词不能为空
当前时间
热门文章
随机推荐
编程相关 Emlog实现网站信息统计的代码
  前言:   有时候想在网页中向访客展示Emlog个人博客的文章数量、评论数量、运行时间等信息 &emsp...
扫描二维码阅读原文
QQ资源吧 January, 01
生成社交图 ×