

那么可以简单处理一下,用mb_substr函数截取前若干字符作为中文摘要即可。
function excerpt_link_modify2() { //为支持中文字符,修改获取摘要函数。
if ( '' == $text ) {
$text = get_the_excerpt('');
$text = strip_shortcodes( $text );
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
$text = strip_tags($text);
$text = mb_substr($text,0,200,'utf-8').'...'; //获取200个字符长作为摘要。
/*
$excerpt_length = apply_filters('excerpt_length', 30);
$words = explode(' ', $text, $excerpt_length + 1);
if (count($words) > $excerpt_length) {
array_pop($words);
array_push($words, '...');
$text = implode(' ', $words);
}
}
*/
}
echo $text;
}
以上是某英文模板中的functions.php中的一个函数。将后面数英文单词的部分取消,直接用mb_substr截取utf-8字符串,200个字符长。
原创文章,作者:苏葳,如需转载,请注明出处:https://www.swmemo.com/452.html
