php - 如何将 post_title 与 post_content 与 html 连接起来 - wordpress

标签 php html mysql wordpress facebook

我正在使用 get_post(post_id) 获取 post_titlepost_content。我想将它们连接起来,post_title 将成为新字符串中的第一段。

例如。

$post_title = 'Hi all, welcome here'
$post_content = 'lorem ipsum bla bla la
new paragraph bla bla bla
new paragrapg lorem ipsum'

我期望这样的结果:

Hi all, welcome here
lorem ipsum bla bla la
new paragraph bla bla bla
new paragrapg lorem ipsum

但我不知道如何在 post_title 之后传递新的段落字符。在数据库 View (mysql)中,没有标签只有空格或 Conceal 字符。我在尝试:

$new_string = $post_title.'/r/n'.$post_content
$new_string = '<p>'.$post_title.'</p>'.$post_content

但它不会起作用。

完成此操作后,我想使用 apply_filters('the_content', $new_content) 获得这个新字符串的正确 View ,并使用 facebook SDK 将其发送到 facebook fanpage。

最佳答案

您应该使用 nl2br() 函数在段落中换行。它会将所有\n 转换为新行。

$new_string = nl2br($post_title.$post_content);

关于php - 如何将 post_title 与 post_content 与 html 连接起来 - wordpress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44630774/

相关文章:

php - 调试内存泄漏,PHP 和 MySQL Blob 流式文件下载

php - 强制某人让他的子类实现接口(interface)的方法

html - 使用 CSS :before to separate anchors

css - 将字段集元素定位在其他元素下

html - ASP.NET MVC 和@Html.RowFor(x => x.Name) 如何添加 CSS

MySQL 用户定义变量和动态列上的 ORDER BY

php - Symfony 2 KNP 菜单 : add CSS class to link

javascript - 如何将fullCalendar中的资源保存到数据库中?

PHP mysql 排序行

MySQL 错误代码 : 1824. 无法打开引用的表