导航菜单

一般我们都需要在想截断摘要的地方插入<!--more-->,但是每篇文章都要手动去添加实在麻烦。其实 Typecho 已经内置了这么一个函数,可以通过限制字数的方式截断摘要。

把模板中的:

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

替换成

<?php $this->excerpt(180, '...'); ?>

其中 180 为摘要字数,... 为省略符号

新版功能,自动输出内容中第一个块级元素中的内容

<?php $this->summary(); ?>

以上来自 http://t.160.me/53.html

有人求助我,想删除摘要中不想要的内容(比如回复可见),这个很简单,早就写过了,现在发出来给大家参考。

$content = $this->excerpt;
$content = shortCodeProcess($content); // 删除你不想要的内容
$abstract = Typecho_Common::fixHtml(Typecho_Common::subStr($content, 0, 180, $trim));
if ($this->password) {
    $abstract = _t(_t("加密文章,请前往内页查看详情"));
}
if (empty($abstract)) $abstract = _t("暂无简介");
echo $abstract;

shortCodeProcess 示例

function shortCodeProcess(text) {
    if (strpos($text, '[hide') !== false) {
        $text = preg_replace('/(?s)<pre[^<]*>.*?<\/pre>(*SKIP)(*F)|\[hide]([^\]]*?)\[\/hide]/', '', $excerpt);
    }
    return $text;
}