@mrwweb是对的,post格式在大多数情况下都非常有用。
作为更通用的解决方案,您可以将the_excerpt()
和the_content()
在里面one 功能:
function wpse_51699_conditional_excerpt( $more_link_text = null, $stripteaser = false )
{
$excerpt = apply_filters( \'the_excerpt\', get_the_excerpt() );
$content = get_the_content( $more_link_text, $stripteaser );
$content = apply_filters(\'the_content\', $content);
$content = str_replace(\']]>\', \']]>\', $content);
$stripped_content = strip_tags( $content );
$content_length = mb_strlen( $stripped_content, \'utf-8\' );
$excerpt_length = mb_strlen( $excerpt, \'utf-8\' );
// $content is just 20% longer than excerpt. Adjust this to your needs.
if ( ( $excerpt_length * 1.2 ) >= $content_length )
{
print $content;
return;
}
echo $excerpt . $more_link_text;
}
在你的主题中,你现在调用…
wpse_51699_conditional_excerpt( sprintf( \'<a href="%1$s">Read more</a>\', get_permalink() ) );
…而不是
the_excerpt();
.