美文网首页
typecho首页列表摘要长度修改

typecho首页列表摘要长度修改

作者: java修炼 | 来源:发表于2019-04-17 10:36 被阅读0次

    typecho的首页文章列表默认显示的是全部内容,如果需要显示部分内容的话,需要在编辑框中增加标签,效果看起来并不是很好。

    在网上找了一段代码,修改如下:

    在index.php中找到

    <?php $this->content('- 阅读剩余部分 -'); ?>
    

    修改为:

        <?php 
    if(preg_match('/<!--more-->/',$this->content)||mb_strlen($this->content, 'utf-8') < 150)
    {
    $this->content('阅读全文...');
    }
    else
    { 
    $c=mb_substr($this->content, 0, 150, 'utf-8');
    $c=preg_replace("/<[img|IMG].*?src=[\'\"](.*?(?:[\.gif|\.jpg|\.jpeg|\.png|\.tiff|\.bmp]))[\'|\"].*?[\/]?>/","",$c);
    if(preg_match('/<pre>/',$c))
    {
    echo $c,'</code></pre>','...';;
    }
    else
    {
    echo $c.'...';
    }
    echo '</br><p class="more"><a href="',$this->permalink(),'" title="',$this->title(),'">阅读全文...</a></p>';
    }
    ?>
    

    相关文章

      网友评论

          本文标题:typecho首页列表摘要长度修改

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