1
私はPHPに新しいですし、the_excerpt()
通話交換するhttp://aaronrussell.co.uk/legacy/improving-wordpress-the_excerpt/から、次のコードを使用しています:私はBrandford Magazine 3.0 themeを使用しています機能の1つのインスタンスを置き換えるフィルターではなく、他の
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');
を、そして2つのインスタンスを持っています私のコードでthe_excerpt()
が呼び出されます。
何とか最初の呼び出しが正しく置き換えられ、improved_trim_excerpt
を使用してテキストを正しく表示していますが、もう1つの呼び出しで古いthe_excerpt()
機能が使用されています。
私はここで何が欠けていますか?
'the_excerpt'は、この新機能が改善しようとしている機能です。リンク先のブログ記事のタイトルをご覧ください。 – Lazer