【问题标题】:Wordpress Plugin, get HTML post contentWordpress 插件,获取 HTML 帖子内容
【发布时间】:2011-08-01 09:45:27
【问题描述】:

我正在构建一个 wordpress 插件,它在管理员保存新帖子时起作用。 我需要获取该帖子的内容,我正在检索 $_POST['content']$_POST['post_content']
这里的问题是我只获取该内容中的文本,我需要 html。

这样,如果我期待像<p>Lorem</p><p>ipsum</p><p>dolor</p> 这样的东西,我会得到Lorem ipsum dolor

有人可以帮帮我吗?

谢谢

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    好吧,正如@ChrisCarson 指出的那样,默认情况下,Wordpress 不会将段落标签存储在数据库中。

    所以,我需要做的是自己解析段落:

    $content = explode(PHP_EOL . PHP_EOL, $this->request['content']);
    $htmlcontent = '';
    foreach($content as $line){
        $htmlcontent .= '<p>' . str_replace(PHP_EOL, '<br />' , $line) . '</p>';
    }   
    

    还是谢谢

    【讨论】:

      【解决方案2】:

      默认情况下,Wordpress 不会在数据库中存储段落标签。试试这个...

      $content = trim(stripslashes($_POST["post_content"]));
      $html = apply_filters("the_content", $content);
      

      【讨论】:

        【解决方案3】:

        来自法典:http://codex.wordpress.org/Template_Tags/the_content#Alternative_Usage

        如果您想获得与 the_content() 返回的相同的输出,请使用 以下代码:

        <?php
        $content = apply_filters('the_content', $content);
        $content = str_replace(']]>', ']]&gt;', $content);
        ?>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2015-06-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多