emlog博客网站信息统计调用代码 - 技术分享 - 五行资源分享网

emlog博客网站信息统计调用代码

作者头像图片

作者: 五行

网络资源搬砖的爱好者

文章二维码手机扫码查看

特别声明:文章多为网络转载,资源使用一般不提供任何帮助,如有侵权请联系!

其实在emlog网站中想更能直观的展现博客得信息内容,由于它官方没有提供特定的模块代码,因此需要自己添加一下查询代码。 以下是别人整理的emlog博客网站调用的统计信息代码。具体可以通过两种方法来实现,各有优缺点,根据具体环境,酌情使用。

 

使用方法:添加到当前使用的主题模板文件中,module.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['comnum']; ?> 条</li>
        <li>隐藏评论数:<?php echo $sta_cache['hidecomnum']; ?> 条</li>
        <li>草稿数:<?php echo $sta_cache['draftnum']; ?> 条</li>
        <li>未审核文章数:<?php echo $sta_cache['checknum']; ?> 条</li>
        <li>微语数:<?php echo $sta_cache['twnum']; ?>条</li> /*微语数在emlog pro版中更换为笔记,并且官方没在提供此类缓存*/
        <li>网站运行:<?php echo floor((time()-strtotime(20160423))/86400); ?> 天</li>  
    </ul>

 

添加到当前使用的主题模板文件中

自查函数,通过SQL语句查询相关数据。缺点:此类查询过多导致加载速度缓慢;优点:实时显示

 

查询函数部分

<?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 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 last_post_log();?></li>   
    </ul>

 

 

emlog博客网站信息统计调用代码-五行资源分享网-第1张图片

本文最后更新于2022-8-13,已超过 1 年没有更新,如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢!
分享到:
打赏
未经允许不得转载:

作者: 五行, 转载或复制请以 超链接形式 并注明出处 五行资源分享网
原文地址: 《emlog博客网站信息统计调用代码》 发布于2022-8-13 21:52
帖子声明: 本站对文章进行整理、排版、编辑,是出于传递信息之目的, 并不意味着赞同其观点或证实其内容的真实性,不拥有所有权,不承担相关法律责任。

评论

在线链接输入图片 打卡按钮图片 私密评论按钮图片 44 + 93 =
乱评论、多次评论者一律禁言帐号或封禁IP
本站已经全面开启缓存,评论查看隐藏内容需等待1分钟后再刷新本页!

 

觉得文章有用就打赏一下文章作者

微信扫一扫打赏

打赏图片