序言

众所周知一个好的站长要处处为访客考虑,服务于人民嘛对不对,自己看着也能舒服一点awa,然后茶栀就把最近想添加上去的东西添加上去了,然后又出了这么一篇文章打算分享出来.

准备工作

进入你的模板文件夹 然后找到page.php 和functions.php 待会要用

教程开始

1.打开functions.php 然后把下面的代码添加进去 在最尾部

//文章阅读时间统计 'www.chazhiwl.cn
function art_time ($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));
  $text = preg_replace("/[^\x{4e00}-\x{9fa5}]/u", "", $rs['text']);
  $text_word = mb_strlen($text,'utf-8');
  echo ceil($text_word / 400);
}

image.png

2.保存文件 然后并打开handsome 主题里面的page.php (其他主题请自行寻找页面标题下面的内容所在的文件)

到时候调用方法为阅读时长 ≈ <?php echo art_time($this->cid); ?>分钟 即可

把下面代码放到你认为合适的地方

             <!--阅读时长-->
             <li class="meta-author"><span class="post-icons"><i data-feather="eye"></i></span><span
             class="meta-value">阅读时长 ≈ <?php echo art_time($this->cid); ?>分钟</span></li>
             <?php if($this->options->commentChoice =='0'): ?>

image.png

3.保存文件 然后刷新你的网站

效果图

image.png

茶栀改好的post.php
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit;
?>

<?php

$rData = Utils::isLock($this);

if ($rData["flag"])
:?>
    <?php
    $data = array();
    $data['title'] = $this->stack[0]['categories'][0]['name'];
    $data['md5'] = Utils::encodeData($rData['password']);
    $data['type'] = "category";
    $data['category'] = $this->stack[0]['categories'][0]['slug'];
    $data['img'] = @$rData['img'];


    $_GET['data']=$data;
    require('libs/Lock.php'); ?>

<?php else: ?>


<?php $this->need('component/header.php'); ?>
    <!-- aside -->
    <?php $this->need('component/aside.php'); ?>
    <!-- / aside -->
<?php if (trim($this->options->postFontSize)!==""): ?>
<style>
    #post-content{
        font-size: <?php echo $this->options->postFontSize."px"; ?>;
    }
</style>
<?php endif; ?>
<!-- <div id="content" class="app-content"> -->
   <a class="off-screen-toggle hide"></a>
   <main class="app-content-body <?php Content::returnPageAnimateClass($this); ?>">
    <div class="hbox hbox-auto-xs hbox-auto-sm">
    <!--文章-->
     <div class="col center-part">
         <!--生成分享图片必须的HTML结构-->
         <?php echo Content::returnSharePostDiv($this) ?>
    <!--标题下的一排功能信息图标:作者/时间/浏览次数/评论数/分类-->
      <?php echo Content::exportPostPageHeader($this,$this->user->hasLogin()); ?>
       <!--文章标题下面的小部件-->
         <?php if (Content::isImageCategory($this->categories)): ?>
         <?php $display = ' style="display:none"'; echo '<small class="text-muted letterspacing indexWords">'
                 .$this->fields->album
                 .'</small>'; ?>
         <?php endif; ?>
         <ul <?php if (isset($display)) echo $display;?> class="entry-meta text-muted list-inline m-b-none small
             post-head-icon">
             <!--浏览数-->
             <li class="meta-views"><span class="post-icons"><i data-feather="user"></i></span><span class="meta-value"><?php echo get_post_view($this) ?><?php _me('次浏览'); ?></span></li>
             <!--发布时间-->
             <li class="meta-date"><span class="post-icons"><i data-feather="clock"></i></span><span class="sr-only"><?php _me("发布时间:") ?></span><time class="meta-value"><?php $this->date(I18n::dateFormat()); ?></time></li>
             <!--阅读时长-->
             <li class="meta-author"><span class="post-icons"><i data-feather="eye"></i></span><span
             class="meta-value">阅读时长 ≈ <?php echo art_time($this->cid); ?>分钟</span></li>
             <?php if($this->options->commentChoice =='0'): ?>
                 <!--评论数-->
                 <li class="meta-comments"><span class="post-icons"><i data-feather="message-circle"></i></span><a
                             class="meta-value" href="#comments"><?php if ($this->allowComment == 1)$this->commentsNum(_mt('暂无评论'), _mt('1 条评论'), _mt('%d 条评论'));else _me("关闭评论") ;?></a></li>
             <?php endif; ?>

             <!--文字数目-->
             <li class="meta-word"><span class="post-icons"><i data-feather="pen-tool"></i></span><span class="meta-value"><?php echo Utils::getWordsOfContentPost($this->text); ?><?php _me('字数'); ?></span></li>
             <!--分类-->
             <li class="meta-categories"><span class="post-icons"><i data-feather="hash"></i></span><span class="sr-only"><?php _me("分类") ?>:</span> <span class="meta-value"><?php $this->category(' '); ?></span></li>
         </ul>
      </header>
      <div class="wrapper-md" id="post-panel">
       <?php Content::BreadcrumbNavigation($this, $this->options->rootUrl); ?>
       <!--博客文章样式 begin with .blog-post-->
       <div id="postpage" class="blog-post">
        <article class="single-post panel">
        <!--文章页面的头图-->
        <?php if (!Content::isImageCategory($this->categories)) echo Content::exportHeaderImg($this); ?>
         <!--文章内容-->
         <div id="post-content" class="wrapper-lg">
         
             <?php Content::postContentHtml($this,
                 $this->user->hasLogin()); ?>


             <?php if ($this->options->adContentPost != ""): ?>
                 <!--文章页脚的广告位-->
                 <?php $this->options->adContentPost(); ?>
             <?php endif; ?>
             <!--文章的页脚部件:打赏和其他信息的输出-->
             <?php echo Content::exportPostFooter($this->modified,$this->options->timezone - idate("Z"),$this); ?>
             <?php if (!empty($this->options->featuresetup) && in_array('payforauthorinpost', $this->options->featuresetup)): ?>
                 <!--打赏模块-->
                 <?php echo Content::exportPayForAuthors(); ?>
             <?php endif; ?>
             <!--/文章的页脚部件:打赏和其他信息的输出-->
         </div>
        </article>
       </div>
       <!--上一篇&下一篇-->
       <nav class="m-t-lg m-b-lg">
        <ul class="pager">
        <?php thePrev($this); ?>   <?php theNext($this); ?>
        </ul>
       </nav>
       <!--评论-->
        <?php $this->need('component/comments.php') ?>
      </div>
     </div>
     <!--文章右侧边栏开始-->
    <?php
    //if (!Content::isImageCategory($this->categories)) {
        $this->need('component/sidebar.php');
    //}
    ?>
     <!--文章右侧边栏结束-->
    </div>
   </main>


    <?php echo Content::returnReadModeContent($this,$this->user->hasLogin()); ?>

<!-- footer -->
    <?php $this->need('component/footer.php'); ?>
      <!-- / footer -->
<?php endif; ?>


最后修改:2020 年 10 月 17 日 10 : 35 PM
如果觉得我的文章对你有用,请随意赞赏