dongzhi4239 2017-06-19 12:37
浏览 417

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

I'm using get_post(post_id) to get post_title and post_content. I would like to concatenate them, that post_title will become first paragraph in new string.

Eg.

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

And I expect result like this:

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

But I don't know how to pass new paragraph character after post_title. In db view (mysql) there are no tags only spaces or hidden charecters. I was trying:

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

But it won't work.

After this operation I would like to use apply_filters('the_content', $new_content) to get right view of this new string and send it to facebook fanpage using facebook SDK.

  • 写回答

1条回答 默认 最新

  • dongzhiyong8577 2017-06-19 13:33
    关注

    You should use nl2br() function to have line breaks in your paragraph. It will convert all to new lines.

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

报告相同问题?

悬赏问题

  • ¥15 科来模拟ARP欺骗困惑求解
  • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
  • ¥15 unity连接Sqlserver
  • ¥15 图中这种约束条件lingo该怎么表示出来
  • ¥15 VSCode里的Prettier如何实现等式赋值后的对齐效果?
  • ¥15 流式socket文件传输答疑
  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式
  • ¥50 关于多次提交POST数据后,无法获取到POST数据参数的问题
  • ¥15 win10,这种情况怎么办
  • ¥15 如何在配置使用Prettier的VSCode中通过Better Align插件来对齐等式?(相关搜索:格式化)