通过ID回显帖子并保留段落


Echo a post by ID with retaining the paragraphs

每当我试图回显帖子的内容时,我都会得到不带html标记的内容。喜欢段落。

有没有办法用段落等来呼应它们?

现在这是我的php代码:

      $post_id = 1231;
      $queried_post = get_post($post_id);
      echo $queried_post->post_content;

这对我有效:

 $post_id = 1226;
 echo apply_filters('the_content', get_post_field('post_content', $post_id));

您可以这样使用来输出带有html标签的内容

echo str_replace("'r", "<br />", get_the_content(''));

使用the_content();echo get_the_content();

因为此函数使用wp筛选器the_content,所以此筛选器使用"wpautop"筛选器。

哪个广告p标签

这是快速

<?php
$post_id = 1226;
$post_local = get_post($post_id);
if($post_local){
    setup_postdata( $post_local );
    echo wpautop(get_the_content());
}
?>