PHP - 将返回值从wp-function转换为String

时间:2014-01-09 03:47:57

标签: php html string wordpress

我在我的网站上使用Wordpress的CMS,我想显示最近的博客帖子,但没有帖子中的HTML标签。我试过以下,但无济于事。

$content = the_content();
$content = strval($content);
echo strip_tags($content, '<p><a>');

返回以下错误:

Parse error: syntax error, unexpected 'the_content' (T_STRING) in C:\xampp\htdocs\wp\wp-content\themes\My-theme\index.php on line 25

1 个答案:

答案 0 :(得分:2)

the_content()将直接回显您的内容,以便您收到错误消息。尝试

$content = get_the_content(); //returns the content so your $content will have all the contents
$content = strval($content);
echo strip_tags($content, '<p><a>');