I noticed that when I call the the_post() or the_content() function from my wordpress template, it automatically parses the database data to replace new lines with <br/>
, wraps the text with <p>
tags etc...There's probably some kind of "format" function within the_post() or the_content().
I wrote a query to directly get posts from the wp_posts. I then print it out like
<?php
$results = $wp->get_results($sql)
foreach($results as $row) echo $row->post开发者_Python百科_content; ?>
Clearly, this data is not parsed by wordpress' "format" function. What is the proper way to output this content such that it undergoes the same "formatting" functions as the_post() or the_content()?
@dpelletier is right, and you can simply apply that function to the $row->post_content
string.
If you want WordPress to do everything it would normally do on the content, including wpautop
and parsing shortcode, use;
$content = apply_filters('the_content', $row->post_content);
There is a function called wpautop()
.
Only adds <p>
and <br/>
, so I'm not sure if there is another formatting function that would do anything else.
精彩评论