美文网首页WordPress博客饥人谷技术博客
Typecho主题改造一些小功能

Typecho主题改造一些小功能

作者: 潮奢馆 | 来源:发表于2019-01-21 20:08 被阅读1次

    Typecho主题改造一些小功能

    • [x] 页面加载耗时
    • [x] 文章最后更新时间
    • [ ] 文章目录
    • [x] 文章字数统计
    • [x] 插件- AMP/MIP for Typecho
    • [x] 插件- Github项目开发展示

    页面加载耗时

    在主题的funcation.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;
        }
    

    然后在主题foot.php文件需要放置加载时间的地方添加
    Site load time is:<?php echo timer_stop();?>

    效果示例:


    image

    文章最后更新时间

    这个实现的比较容易,在想要添加的地方加上下面的代码就ok类
    最后编辑时间为:<?php echo date('F jS , Y \\a\t H:i a', $this->modified);?>

    效果示例:


    image

    文章目录

    这个暂时还没有搞 待完成

    文章字数统计

    在主题的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); ?>
    效果示例:

    image

    插件- AMP/MIP for Typecho

    一键生成符合Google AMP/Baidu MIP标准相关页面的插件,开启后可以进一步优化Google、Baidu的搜索结果。

    演示:https://sb.ioinn.cn/ampindex/

    AMP首页为 http(s)://xxx/ampindex/
    AMP页面为 http(s)://xxx/amp/slug/
    MIP页面为 http(s)://xxx/mip/slug/

    开发:https://github.com/holmesian/Typecho-AMP

    插件- Github项目开发展示

    基础用法 编辑器内之间插入内容
    <gb>jzwalk/GHbutton</gb>

    完整例子:

    <gb user="jzwalk" type="download" count="1" size="1" lang="cn" width="370">
    GHbutton
    </gb>
    

    效果示例:


    image

    详细介绍:Typecho开发展示插件GHbutton1.0.4更新

    来源地址:http://sb.ioinn.cn/21.html

    相关文章

      网友评论

        本文标题:Typecho主题改造一些小功能

        本文链接:https://www.haomeiwen.com/subject/klgpzxtx.html