仅获取第一段(从页面)

时间:2019-07-09 22:47:42

标签: wordpress

我试图从首页到首页只获取第一段,尝试了很少的代码,但没有走运

function get_first_paragraph(){
global $post;
$str = wpautop( get_the_content() );
$str = substr( $str, 0, strpos( $str, '</p>' ) + 4 );
$str = strip_tags($str, '<a><strong><em>');
return '<p>' . $str . '</p>';
}
<?php echo get_first_paragraph(); ?>

1 个答案:

答案 0 :(得分:0)

使用此:

<?php

$content = get_the_content();
$trimmed_content = wp_trim_words( $content, 50, NULL );
echo $trimmed_content;

?>
相关问题