emlog网站信息统计代码

  • 内容
  • 相关

以下代码可添加到当前使用的主题模板文件中,如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>

把下面的代码添加到主题的module.php文件中(自编函数,通过SQL语句查询相关数据。缺点:加载速度较缓存类慢;优点:实时显示):

    <?php
    	//统计文章总数
    	function count_log_all(){
    		$db = Database::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 = Database::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 = Database::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 = Database::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 = Database::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 = Database::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 = Database::getInstance();
    		$data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "comment");
    		return $data['total'];
    	}
    	//统计友链总数
    	function count_link_all(){
    		$db = Database::getInstance();
    		$data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "link");
    		return $data['total'];
    	}
     
    	//统计微语评论总数
    	function count_treply_all(){
    		$db = Database::getInstance();
    		$data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "reply");
    		return $data['total'];
    	}
     
    	//统计分类总数
    	function count_sort_all(){
    		$db = Database::getInstance();
    		$data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "sort");
    		return $data['total'];
    	}
     
    	//统计子分类数
    	function count_sort_mod(){
    		$db = Database::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 = Database::getInstance();
    		$data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "tag");
    		return $data['total'];
    	}
     
    	//统计微语总数
    	function count_tw_all(){
    		$db = Database::getInstance();
    		$data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "twitter");
    		return $data['total'];
    	}
     
    	//统计用户总数
    	function count_user_all(){
    		$db = Database::getInstance();
    		$data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "user");
    		return $data['total'];
    	}
     
    	//统计管理员总数
    	function count_user_admin(){
    		$db = Database::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 = Database::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 = Database::getInstance();
    		$data = $db->once_fetch_array("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "attachment");
    		return $data['total'];
    	}
     
    	//最后发表文章时间 
    	function last_post_log(){
    		$db = Database::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网站信息统计代码 - https://stdym.com/post-19.html

发表评论

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