2011-08-01 27 views
4

我正在建立一個wordpress插件,當管理員保存一個新的職位時的行爲。 我需要獲取該帖子的內容,我正在檢索$_POST['content']$_POST['post_content']
這裏的問題是,我只收到該內容中的文本,我需要的HTML。WordPress的插件,獲取HTML發佈內容

這樣,如果我期待像<p>Lorem</p><p>ipsum</p><p>dolor</p>這樣的東西,我會得到Lorem ipsum dolor

有人可以幫我嗎?

謝謝

回答

4

那麼,正如@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>'; 
} 

感謝反正

1

WordPress的默認情況下不會在數據庫中存儲段落標籤。試試這個......

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