emlog网站信息统计代码

        有时候想在网页中向访客展示emlog博客的文章数量、评论数量、运行时间等信息,但emlog后台侧边栏没有提供相关的模块,因此需要博主自主添加博客统计信息代码。下面是博客吧整理的emlog网站信息统计代码,已在emlog 5.3.x上测试可用。

        方法一:官方缓存类统计代码。优点:加载速度快;缺点:可能信息更新不及时。 把以下代码添加到当前使用的主题模板文件中,如side.php文件:

<?php $sta_cache = Cache::getInstance()->readCache('sta'); /*必须添加*/ ?>
<ul>
	<li>文章总数:<?php echo $sta_cache['lognum']; ?> 篇</li>
	<li>评论总数:<?php echo $sta_cache['comnum_all']; ?> 条</li>
	<li>闲言碎语:<?php echo $sta_cache['twnum']; ?>条</li>		
	<li>网站运行:<?php echo floor((time()-strtotime(20160423))/86400); ?> 天</li>	
</ul>

        附:$sta_cache[‘参数’]中的参数可选如下:             lognum游客可见日志总数             draftnum草稿,也就是隐藏文件数量             comnum未隐藏的评论数量             comnum_all所有评论数量             hidecomnum被隐藏的评论数量             twnum微语数量             checknum未审核的文章数量         方法二:自编函数,通过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>

            原文地址:森七博客

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏Java帮帮-微信公众号-技术文章全总结

【数据库】MySQL进阶一、主外键讲解

MySQL进阶主外键讲解 1.什么是外键: 主键:是唯一标识一条记录,不能有重复的,不允许为空,用来保证数据完整性 外键:是另一表的主键, 外键可...

3717
来自专栏乐沙弥的世界

Oracle 索引监控(monitor index)

      合理的为数据库表上创建战略性索引,可以极大程度的提高了查询性能。但事实上日常中我们所创建的索引并非战略性索引,恰恰是大量冗余或是根本没有用到的索引耗...

1011
来自专栏KaliArch

MySQL常用操作

1723
来自专栏Android相关

SQLite---使用触发器(Trigger)

当数据库中的数据太多时,往往需要进行清理,将一些过时的数据删除,但是往往找不到合适的时机进行清理。于是SQLite提供了Trigger,当某些事件发生时,可以触...

1535
来自专栏数据库新发现

Oracle9i新特性-索引监视及注意事项[修正版]

Last Updated: Saturday, 2004-12-04 10:28 Eygle

943
来自专栏Netkiller

MySQL 大数据操作注意事项

MySQL 大数据操作注意事项 http://netkiller.github.io/journal/mysql.parallel.html 摘要 ---- 目...

3928
来自专栏JavaEdge

MySQL count()函数及其优化count(1),count(*),count(字段)区别

4486
来自专栏个人分享

hiveql笔记(一)

create table if not exists mydb.employees{

942
来自专栏数据和云

变与不变: Undo构造一致性读的例外情况

嘉年华听了恩墨学院的一个主题:《重现ORA-01555 细说Oracle 12c Undo数据管理》,吕星昊老师介绍了UNDO的概念以及ORA-1555的产生,...

842
来自专栏乐沙弥的世界

使用 Oracle Datapump API 实现数据导出

  Oracle Datapump API 是基于PL/SQL实现的,是命令行方式下的补充。使用Datapump API可以将其逻辑备份特性将其集成到应用程序当...

1814

扫码关注云+社区

领取腾讯云代金券