替换_content();带有echo wpse\\u limit\\u content();
function wpse_limit_content() {
$content = $post->post_content;
$MAX_LENGTH = 100;
if ( strlen( $content ) <= $MAX_LENGTH )
return apply_filters(\'the_content\', $content );
$s2 = substr( $content, 0, $MAX_LENGTH );
$s3 = preg_split( "/\\s+(?=\\S*+$)/", $s2 );
$s4 = $s3[0];
return apply_filters( \'the_excerpt\', $s4 );
}
如果字符串太长,它会对其进行修剪,以获得一个100个字符的摘录。
您也可以这样做:
$content = $post->post_content;
if (strlen( $content > 100 ) {
the_excerpt();
} else {
the_content();