emlog网站首页侧边栏文章统计,统计代码,博客文章数量、评论数量、运行时间等信息

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

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

<?php $stacache = Cache::getInstance()->readCache('sta'); /*必须添加*/ ?>
<ul>
<li>文章总数:<?php echo $stacache['lognum']; ?> 篇</li>
<li>评论总数:<?php echo $stacache['comnumall']; ?> 条</li>
<li>闲言碎语:<?php echo $stacache['twnum']; ?>条</li>
<li>网站运行:<?php echo floor((time()-strtotime(20160423))/86400); ?> 天</li>
</ul>
   附:$stacache[‘参数’]中的参数可选如下:
            lognum游客可见日志总数
            draftnum草稿,也就是隐藏文件数量
            comnum未隐藏的评论数量
            comnumall所有评论数量
            hidecomnum被隐藏的评论数量
            twnum微语数量
            checknum未审核的文章数量
        方法二:自编函数,通过SQL语句查询相关数据。缺点:加载速度较缓存类慢;优点:实时显示

        把下面的代码添加到主题的module.php文件中:

<?php
//统计文章总数
function countlogall(){
$db = MySql::getInstance();
$data = $db->oncefetcharray("SELECT COUNT(*) AS total FROM " . DBPREFIX . "blog WHERE type = 'blog'");
return $data['total'];
}
 
//置顶文章数
function countlogtop(){
$db = MySql::getInstance();
$data = $db->oncefetcharray("SELECT COUNT(*) AS total FROM " . DBPREFIX . "blog WHERE  top = 'y' or sortop = 'y' AND type = 'blog'");
return $data['total'];
}
//隐藏文章数
function countloghide(){
$db = MySql::getInstance();
$data = $db->oncefetcharray("SELECT COUNT(*) AS total FROM " . DBPREFIX . "blog WHERE hide = 'y' AND type = 'blog'");
return $data['total'];
}
 
//未审核文章数
function countlogcheck(){
$db = MySql::getInstance();
$data = $db->oncefetcharray("SELECT COUNT(*) AS total FROM " . DBPREFIX . "blog WHERE checked = 'n' AND type = 'blog'");
return $data['total'];
}
 
//加密文章数
function countlogpass(){
$db = MySql::getInstance();
$data = $db->oncefetcharray("SELECT COUNT(*) AS total FROM " . DBPREFIX . "blog WHERE  password !='' AND type = 'blog'");
return $data['total'];
}
 
//统计页面总数
function countpageall(){
$db = MySql::getInstance();
$data = $db->oncefetcharray("SELECT COUNT(*) AS total FROM " . DBPREFIX . "blog WHERE type = 'page'");
return $data['total'];
}
 
//统计评论总数
function countcomall(){
$db = MySql::getInstance();
$data = $db->oncefetcharray("SELECT COUNT(*) AS total FROM " . DBPREFIX . "comment");
return $data['total'];
}
//统计友链总数
function countlinkall(){
$db = MySql::getInstance();
$data = $db->oncefetcharray("SELECT COUNT(*) AS total FROM " . DBPREFIX . "link");
return $data['total'];
}
 
//统计微语评论总数
function counttreplyall(){
$db = MySql::getInstance();
$data = $db->oncefetcharray("SELECT COUNT(*) AS total FROM " . DBPREFIX . "reply");
return $data['total'];
}
 
//统计分类总数
function countsortall(){
$db = MySql::getInstance();
$data = $db->oncefetcharray("SELECT COUNT(*) AS total FROM " . DBPREFIX . "sort");
return $data['total'];
}
 
//统计子分类数
function countsortmod(){
$db = MySql::getInstance();
$data = $db->oncefetcharray("SELECT COUNT(*) AS total FROM " . DBPREFIX . "sort WHERE pid != 0");
return $data['total'];
}
 
//统计标签总数
function counttagall(){
$db = MySql::getInstance();
$data = $db->oncefetcharray("SELECT COUNT(*) AS total FROM " . DBPREFIX . "tag");
return $data['total'];
}
 
//统计微语总数
function counttwall(){
$db = MySql::getInstance();
$data = $db->oncefetcharray("SELECT COUNT(*) AS total FROM " . DBPREFIX . "twitter");
return $data['total'];
}
 
//统计用户总数
function countuserall(){
$db = MySql::getInstance();
$data = $db->oncefetcharray("SELECT COUNT(*) AS total FROM " . DBPREFIX . "user");
return $data['total'];
}
 
//统计管理员总数
function countuseradmin(){
$db = MySql::getInstance();
$data = $db->oncefetcharray("SELECT COUNT(*) AS total FROM " . DBPREFIX . "user WHERE role = 'admin'");
return $data['total'];
}
 
//统计作者总数
function countuserwriter(){
$db = MySql::getInstance();
$data = $db->oncefetcharray("SELECT COUNT(*) AS total FROM " . DBPREFIX . "user WHERE role = 'writer'");
return $data['total'];
}
 
//统计附件总数
function countattall(){
$db = MySql::getInstance();
$data = $db->oncefetcharray("SELECT COUNT(*) AS total FROM " . DBPREFIX . "attachment");
return $data['total'];
}
 
//最后发表文章时间 
function lastpostlog(){
$db = MySql::getInstance();
$sql = "SELECT * FROM " . DBPREFIX . "blog WHERE type='blog' ORDER BY date DESC LIMIT 0,1";
$res = $db->query($sql);
$row = $db->fetcharray($res);
$date = date('Y-n-j H:i',$row['date']);
return $date;       
};
?>
调用代码:

<ul>
<li>文章总数:<?php echo countlogall();?></li>
<li>置顶文章:<?php echo countlogtop();?></li>
<li>隐藏文章:<?php echo countloghide();?></li>
<li>待审文章:<?php echo countlogcheck();?></li>
<li>加密文章:<?php echo countlogpass();?></li>
<li>页面总数:<?php echo countpageall();?></li>
<li>评论总数:<?php echo countcomall();?></li>
<li>友链总数:<?php echo countlinkall();?></li>
<li>微语评论:<?php echo counttreplyall();?></li>
<li>分类总数:<?php echo countsortall();?></li>
<li>子分类数:<?php echo countsortmod();?></li>
<li>标签总数:<?php echo counttagall();?></li>
<li>微语总数:<?php echo counttwall();?></li>
<li>用户总数:<?php echo countuserall();?></li>
<li>管理员数:<?php echo countuseradmin();?></li>
<li>作者总数:<?php echo countuserwriter();?></li>
<li>附件总数:<?php echo countattall();?></li>
<li>最后更新:<?php echo lastpostlog();?></li>
</ul>
CTRL+D快速收藏,欢迎常来喔

本文标签:这篇文章木有标签

本文标题: emlog网站首页侧边栏文章统计,统计代码,博客文章数量、评论数量、运行时间等信息

本文链接: https://www.zyoua.com/Website/1143.html

版权声明:若无特殊注明,本文皆为《 有啊 》原创,转载请保留文章出处。

发表评论

电子邮件地址不会被公开。 必填项已用*标注

允许邮件通知
既然没有吐槽,那就赶紧抢沙发吧!