共有两种方法:
1. 修改对应主题的index.php(或者home.php)文件中的代码
the_content(__('Read more...', 'inove')); ?>
the_content为获取文章全部内容的API。
the_excerpt为获取文章摘要的API。因为WordPress为英文而写的,所以会导致摘要出现过大过小的情况。主要因为为该方法是根据出现了多少个空格后而截断。源码如下:
function wp_trim_excerpt($text) {
$raw_excerpt = $text;
if ( '' == $text ) {
$text = get_the_content('');
$text = strip_shortcodes( $text );
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
$text = strip_tags($text);
$excerpt_length = apply_filters('excerpt_length', 55);
$words = explode(' ', $text, $excerpt_length + 1);
if (count($words) > $excerpt_length) {
array_pop($words);
array_push($words, '[...]');
$text = implode(' ', $words);
}
}
return apply_filters('wp_trim_excerpt', $text, $raw_excerpt);
}
从中我们可以看出,英文摘要是显示出现了55个空格之前的内容,对于中文来说已经完全不在适合。
所以可以自己写对应的方法来替换对应的逻辑。
下面给大家讲一个简单的办法,首先下载并安装中文 WordPress 工具箱
然后修改mulberrykit.php文件中对应的字数:
function mul_excerpt ($excerpt) {
$myexcerpt = substr($excerpt,0,255);
return utf8_trim($myexcerpt) . '... ';
}
add_filter('the_excerpt', 'mul_excerpt');
add_filter('the_excerpt_rss', 'mul_excerpt');
默认为255个字符,我把他改为了255*3。 显示效果就是现在的样子啦。当然你可以根据你的需要进行合适的修改。