2014-12-04 73 views
0

我在wordpress之外创建一个文件,但我想获得wordpress帖子等。我创建了以下这个文件,我想要它做,但它缺少第P标签。如果我通过wp-admin查看这篇文章,它看起来很好。如果我通过这个功能它能源部鼻涕查看一下找到wordpress missing P标签

ini_set('display_errors','on'); 

//Global WordPress 
global $wpdb; 

if(!isset($wpdb)) 
{ 
    require_once('wp-config.php'); 
    require_once('wp-load.php'); 
    require_once('wp-includes/wp-db.php'); 
} 

$args = array("post_title" => $_GET['name'],"category_name"=>"knowledge-map"); 
$query = get_posts($args); 


$posttitle = $_GET['name']; 
$postid = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_title = '" . $posttitle . "'"); 
$post = $getpost= get_post($postid); 

$post_title = sanitize_post_field('post_title', $post->post_title, $post->ID, 'display'); 
$post_content = sanitize_post_field('post_content', $post->post_content, $post->ID, 'display'); 

//$postcontent= $getpost->post_content; 
//setup_postdata($getpost); 
$data = $post->post_content; 
//foreach ($getpost as $post) : setup_postdata($post); 
    //$data = get_the_title() . the_content(); 
//endforeach; 
wp_reset_postdata(); 


echo $data; 

回答

3

post_content不会显示正确的格式...基本上如初。您需要the_content过滤器适用于它:

echo apply_filters('the_content', $data); 

这里就是它提到in the Codex

虽然wpautop其中存在的新线只会增加段落标记,the_content运行一堆核心过滤器(包括wpautop)的。从the sourcethe_content包括:

add_filter('the_content', 'wptexturize'  ); 
add_filter('the_content', 'convert_smilies' ); 
add_filter('the_content', 'convert_chars'  ); 
add_filter('the_content', 'wpautop'   ); 
add_filter('the_content', 'shortcode_unautop' ); 
add_filter('the_content', 'prepend_attachment'); 
+0

什么用'回声wpautop($ POST_CONTENT)的differene的自动格式;'? – shorif2000 2014-12-04 12:51:56

+0

'wpautop'只有在有新行时才会应用格式。该过滤器也将适用于其他一些案件的格式。看到我上面的编辑。 – rnevius 2014-12-04 12:55:36

+0

'wpautop'包含在'the_content'过滤器中。 – rnevius 2014-12-04 12:57:31

2

你也可以使用wpauto,它使用在WordPress文本

echo wpautop($post_content);