1
我是新来的PHP,并使用从http://aaronrussell.co.uk/legacy/improving-wordpress-the_excerpt/下面的代码替换the_excerpt()
电话是:过滤器替换功能的一个实例而不是其他
function improved_trim_excerpt($text) {
global $post;
if ('' == $text) {
$text = get_the_content('');
$text = apply_filters('the_content', $text);
$text = str_replace('\]\]\>', ']]>', $text);
$text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
$text = strip_tags($text, '<p>');
$excerpt_length = 80;
$words = explode(' ', $text, $excerpt_length + 1);
if (count($words)> $excerpt_length) {
array_pop($words);
array_push($words, '[...]');
$text = implode(' ', $words);
}
}
return $text;
}
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'improved_trim_excerpt');
我现在用的是Brandford Magazine 3.0 theme,并有两个实例the_excerpt()
调用我的代码。
不知怎的,第一个电话正在被正确地替换,正在按照预期使用improved_trim_excerpt
正确显示文本,但另一个电话仍然使用旧的the_excerpt()
功能。
我在这里可能会错过什么?
'the_excerpt'是这个新函数试图改进的功能。查看我链接到的博客文章的标题。 – Lazer 2012-03-10 09:11:03