2010-12-10 75 views
4

我用了很多的功能:PHP - 如何獲得`<?php the_content(); ?>`作爲一個字符串或者把它變成一個字符串

get_search_query() 

爲了從搜索返回的值,並可以修改和使用的字符串。

我需要知道一個函數來獲得<?php the_content(); ?>作爲一個字符串或如何將該函數返回到一個字符串。

內容只是一個帶有段落標籤的簡單單詞,但使用該功能我也收到了標籤,我只想得到文本,以便我可以將其添加到超鏈接。

回答

6

我認爲你正在尋找get_the_content(),這是有據可查的:http://codex.wordpress.org/Function_Reference/the_content

+3

雖然這*是*可能是最好的辦法,注意`get_the_content()`是*不*只是`the_content() `返回內容而不是打印。一個重要的區別是`get_the_content()`不會過濾內容。因此,例如,如果您使用簡碼來嵌入視頻,聯繫表單等,則默認情況下這些方法無法使用。您還需要在內容上運行`apply_filters(「the_content」,...)`。來自WP Codex的更多信息:https://codex.wordpress.org/Function_Reference/the_content#Alternative_Usage – rinogo 2015-08-17 21:37:54

1

不知道WP,但隱含的命名約定建議get_the_content()。額外的谷歌搜索顯示變化get_the_content_with_formatting

然而,另一種方法是將the_content()換成ob_start()ob_get_contents()+ob_end()。後者返回任何print輸出,直到那時。

1

您應該使用get_the_content()以使其獲得可以格式化的字符串。

3

如果您需要將其存儲在HTML格式的變量做到這一點

apply_filters('the_content',$post->post_content) 
+2

我有一個問題,您的解決方案解決了它。謝謝 :) – IamGhale 2014-06-07 15:21:43

相關問題