在制作的过程当中,我们经常需要截取限定字数的文章摘要,有些朋友喜欢使用 more 标签来截取,还有一些朋友喜欢手动给每篇文章添加摘要,然后使用 the_excerpt() 函数输出,但是这样耗时耗力,而且效果也不是特别好。91wordpress的站长结合多年wordpress制作经验,向大家介绍一个简单的方法:
1. 切换到主题所在目录,打开functions.php,加入如下代码:
',']]>',$text)); $text = trim($text); if (strlen($text) > $max_char) { $text = substr($text,$max_char+1); $text = utf8_conver($text); $text = str_replace(array("\r","\n"),' ',$text); $text .= $more_text; if ($limit_type == 'content'){ $text = "".$text."
"; $text .= "阅读全文"; } echo $text; } else { if ($limit_type == 'content'){$text = "".$text."
";} echo $text; }}function utf8_conver($str) { $len = strlen($str); for ($i=strlen($str)-1; $i>=0; $i-=1){ $hex .= ' '.ord($str[$i]); $ch = ord($str[$i]); if (($ch & 128)==0) return(substr($str,$i)); if (($ch & 192)==192) return(substr($str,$i)); } return($str.$hex);}?>''""阅读全文"""