事实上the_excerpt() 呼叫get_the_excerpt(), 哪些输出$post->post_excerpt.
还有一件事:你不应该使用add_filter() 而不是add_action()?
为什么要使用the_excerpt()/the_content()/the_title(), 而不是设置$content = get_the_excerpt() 等,然后返回$content? e、 g.这:
add_filter( \'the_content\', \'myFunc\' );
function myFunc ( $content ) {
the_excerpt();
}
。。。通常写为:
add_filter( \'the_content\', \'myFunc\' );
function myFunc ( $content ) {
$content = get_the_excerpt();
return $content;
}
不确定这是否能解决递归循环的问题。。。
EDIT
你最后的评论给了我一个想法:为什么不直接传递$内容呢
wp_trim_excerpt() 那就完了?
add_filter( \'the_content\', \'myFunc\' );
function myFunc( $content ) {
$excerpt = wp_trim_excerpt( $content );
return $excerpt;
}
EDIT 2
好了,我现在同意你了。我们推出自己的摘录功能怎么样?
add_filter( \'the_content\', \'myFunc\' );
function myFunc( $content ) {
$text = strip_shortcodes( $content );
$text = str_replace(\']]>\', \']]>\', $text);
$text = strip_tags($text);
$excerpt_length = apply_filters(\'excerpt_length\', 55);
$excerpt_more = apply_filters(\'excerpt_more\', \' \' . \'[...]\');
$words = preg_split("/[\\n\\r\\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
if ( count($words) > $excerpt_length ) {
array_pop($words);
$text = implode(\' \', $words);
$text = $text . $excerpt_more;
} else {
$text = implode(\' \', $words);
}
return $text;
}