PHP - 如何获得`<! - ?php the_content(); ? - >`作为字符串或将其转换为字符串

时间:2010-12-10 03:33:57

标签: php wordpress

我使用了很多功能:

get_search_query() 

获取搜索返回的值,并能够修改和使用字符串。

我需要知道一个函数来将<?php the_content(); ?>作为字符串或如何将该函数返回到字符串中。

内容只是一个带有段落标签的简单单词,但使用该功能我也得到了标签,我想得到文本,所以我可以将它添加到超链接。

5 个答案:

答案 0 :(得分:8)

我认为您正在寻找get_the_content(),其中有详细记录:http://codex.wordpress.org/Function_Reference/the_content

答案 1 :(得分:3)

如果您需要将其存储在带有html格式的变量中,请执行此操作

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

答案 2 :(得分:2)

不知道WP,但隐含的命名约定会建议get_the_content()。其他Google搜索显示变体get_the_content_with_formatting

然而,另一种方法是将the_content()包装到ob_start()ob_get_contents()+ob_end()中。后者返回在此之前所做的任何print输出。

答案 3 :(得分:1)

你应该使用get_the_content()以使其成为一个字符串,你可以格式化。

答案 4 :(得分:0)

$the_post = get_post();
$the_post->post_content;

使用此方法可以获得的完整列表:

[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] =>