前端代码的一些插入


在 functions.php 中加入以下代码:

   /**
     * 加载时间
     * @return bool
     */
    function timer_start() {
        global $timestart;
        $mtime     = explode( ' ', microtime() );
        $timestart = $mtime[1] + $mtime[0];
        return true;
    }
    timer_start();
    function timer_stop( $display = 0, $precision = 3 ) {
        global $timestart, $timeend;
        $mtime     = explode( ' ', microtime() );
        $timeend   = $mtime[1] + $mtime[0];
        $timetotal = number_format( $timeend - $timestart, $precision );
        $r         = $timetotal < 1 ? $timetotal * 1000 . " ms" : $timetotal . " s";
        if ( $display ) {
            echo $r;
        }
        return $r;
    }

然后,在模板中引用:

<?php echo timer_stop();?>

前台输出相关统计

1.<?php Typecho_Widget::widget('Widget_Stat')->to($stat); ?>
2.<p><?php _e('氪星人自 <strong>2013</strong> 年建站以来,截至 %s 在设定的 <strong>%s</strong> 个分类
3.和 <strong>%s</strong> 个页面中,
4.发布了 <strong>%s</strong> 篇文章,收到了 <strong>%s</strong> 条评论。
5.', date('Y年n月j日G时i分'), $stat->categoriesNum, $stat->publishedPagesNum, $stat->publishedPostsNum, $stat->publishedCommentsNum); ?></p>

文章字数统计

在主题的functions.php中写入代码:

function  art_count ($cid){
$db=Typecho_Db::get ();
$rs=$db->fetchRow ($db->select ('table.contents.text')->from ('table.contents')->where ('table.contents.cid=?',$cid)->order ('table.contents.cid',Typecho_Db::SORT_ASC)->limit (1));
echo mb_strlen($rs['text'], 'UTF-8');
}

然后在想要添加的地方之间加调用就ok

<?php echo art_count($this->cid); ?>

总访客数统计代码
functions.php 中,添加以下统计代码

//总访问量
    function theAllViews()
        {
            $db = Typecho_Db::get();
            $row = $db->fetchAll('SELECT SUM(VIEWS) FROM `typecho_contents`');
                echo number_format($row[0]['SUM(VIEWS)']);
        }

然后在你需要显示的位置(如:footer.php sidebar.php 等)插入以下调用代码

<?php echo theAllViews();?></span><?php _me("访客总数") ?>

添加版权声明

本文作者:萧亮 Blog

本文链接:options->title();?> 所有,未经允许不得转载!

声明:GhostKylin‘S BLOG|版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - 前端代码的一些插入


你好!世界!XladminShell箱子仅供个人学习使用务必遵守《网络安全法》