2 php wordpress formatting strip
我通过以下代码在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 ); ?>
Run Code Online (Sandbox Code Playgroud)
当您使用get_post_field提取帖子内容时,不会应用自动过滤器:http://codex.wordpress.org/Function_Reference/wpautop
您可以在设置后添加以下行来自行应用所有内容过滤器$content:
$content = apply_filters('the_content', $content);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1762 次 |
| 最近记录: |