PHP - 我如何获得`<?php the_content(); ?>` 作为字符串或将其转换为字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4405395/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP - How do I get `<?php the_content(); ?>` as a string or turn it into a string
提问by lisovaccaro
I use a lot the function:
我使用了很多功能:
get_search_query()
To get the value returned from searches and to be able to modify and use the string.
获取搜索返回的值并能够修改和使用字符串。
I need to know a function to get <?php the_content(); ?>
as a string or how to turn what that function returns into a string.
我需要知道一个函数<?php the_content(); ?>
作为字符串获取,或者如何将该函数返回的内容转换为字符串。
The content is just a simple word with paragraph tags but using that function I also get the tags, I want to get just the text so I can add it to a hyperlink.
内容只是一个带有段落标签的简单单词,但使用该功能我也可以获取标签,我只想获取文本以便我可以将其添加到超链接中。
回答by deceze
I think you're looking for get_the_content()
, which is well documented: http://codex.wordpress.org/Function_Reference/the_content
我认为你正在寻找get_the_content()
,这是有据可查的:http: //codex.wordpress.org/Function_Reference/the_content
回答by Mark
If you need to store it in a variable with html formatting do this
如果您需要将其存储在具有 html 格式的变量中,请执行此操作
apply_filters('the_content',$post->post_content)
回答by mario
Don't know WP, but the implied naming convention would suggest get_the_content()
. Additional googling reveals a variation get_the_content_with_formatting
不知道 WP,但隐含的命名约定会建议get_the_content()
. 额外的谷歌搜索揭示了一个变体get_the_content_with_formatting
An alternative would be however to wrap the_content() into ob_start()
and ob_get_contents()+ob_end()
. The latter returns any print
output made until then.
然而,另一种方法是将 the_content() 包装到ob_start()
and 中ob_get_contents()+ob_end()
。后者返回print
在此之前所做的任何输出。
回答by moffepoffe
You should use get_the_content() in order to make get it into a string, which you can format.
您应该使用 get_the_content() 将其转换为可以格式化的字符串。
回答by Rossitten
$the_post = get_post();
$the_post->post_content;
Full list of things you can get using this method:
使用此方法可以获得的完整列表:
[ID] =>
[post_author] =>
[post_date] =>
[post_date_gmt] =>
[post_content] =>
[post_title] =>
[post_excerpt] =>
[post_status] =>
[comment_status] =>
[ping_status] =>
[post_password] =>
[post_name] =>
[to_ping] =>
[pinged] =>
[post_modified] =>
[post_modified_gmt] =>
[post_content_filtered] =>
[post_parent] =>
[guid] =>
[menu_order] =>
[post_type] =>
[post_mime_type] =>
[comment_count] =>
[filter] =>