WordPress在调用扩展内容时保留格式


Wordpress retain formatting when calling extended content?

我通过下面的代码在Wordpress中调用内容。从本质上讲,我将帖子的内容分为三个部分;1. 标签前, 2.在标签和 3.帖子画廊。到目前为止,我拥有的代码可以完美地获取内容,但是我遇到了一个问题,因为所有格式标签(特别是p)都被剥离了。有没有办法保留这些?

谢谢

<?php 
// Fetch post content
$content = get_post_field( 'post_content', get_the_ID() );
// Get content parts
$content_parts = get_extended( $content );
?>
<p>
<?php echo $content_parts['main']; // Output content before <!--more--> ?>  
</p>
<p class="read-more">
<?php echo strip_shortcodes($content_parts['extended']); // Output content after <!--more--> ?> 
</p>
<button>Read More</button>
<?php $gallery = get_post_gallery_images( $post ); ?>

使用 get_post_field 拉取帖子内容时,不会应用 autop 过滤器:http://codex.wordpress.org/Function_Reference/wpautop

您可以在设置$content后添加以下行来自行应用所有内容过滤器:

$content = apply_filters('the_content', $content);