Tabby

[Typecho]首页摘要自动截取样式
带图片输出: <?php if(preg_match('/<!--more-->/',$thi...
扫描右侧二维码阅读全文
12
2018/06

[Typecho]首页摘要自动截取样式

带图片输出:

<?php 
if(preg_match('/<!--more-->/',$this->content)||mb_strlen($this->content, 'utf-8') < 270)
{
$this->content('阅读全文...');
}
else
{ 
$c=mb_substr($this->content, 0, 270, 'utf-8');
echo $c.'...';
echo '</br><p class="more"><a href="',$this->permalink(),'" title="',$this->title(),'">阅读全文...</a></p>';
}
?>

不带图片输出:

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

截取代码部分输出:

<?php 
if(preg_match('/<!--more-->/',$this->content)||mb_strlen($this->content, 'utf-8') < 270)
{
$this->content('阅读全文...');
}
else
{ 
$c=mb_substr($this->content, 0, 270, '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>';
}
?>

文章有帮助?
扫一扫拿红包 → 支付宝打赏 → 获取现金红包
您的支持是我最大的动力!
Last modification:June 14th, 2018 at 05:18 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment