WordPresssets up a default filter for get_the_excerpt: wp_trim_excerpt(). 正是这个函数将generate an excerpt from the content "if needed". 如果您不希望出现这种行为,只需解开过滤器即可:
add_action( \'init\', \'wpse17478_init\' );
function wpse17478_init()
{
remove_filter( \'get_the_excerpt\', \'wp_trim_excerpt\' );
}
现在
get_the_excerpt() 将只返回
post_excerpt 数据库字段。如果要在某个内容为空时返回,只需检查以下情况:
add_filter( \'get_the_excerpt\', \'wpse17478_get_the_excerpt\' );
function wpse17478_get_the_excerpt( $excerpt )
{
if ( \'\' == $excerpt ) {
return \'No excerpt!\';
}
return $excerpt;
}
没有必要打电话
get_the_excerpt() - 它甚至可能引入无休止的递归,因为它会再次应用您的过滤器!