我正在wordpress之外创建一个文件,但我想获得wordpress post等。我创建了以下内容,我想要它做什么,但它缺少P
标签。如果我通过wp-admin查看此帖子,它看起来很好。如果我通过这个功能查看它,它会发现鼻涕看起来
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;
答案 0 :(得分:3)
post_content
无法显示正确的格式...基本上永远。您需要对其应用the_content
过滤器:
echo apply_filters('the_content', $data);
这里提到in the Codex。
虽然wpautop
只会在新行存在的情况下添加段落标记,但the_content
会运行一堆核心过滤器(包括wpautop
)。来自the source,the_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' );
答案 1 :(得分:2)
您还可以使用wpauto
,它在wordpress中用于自动格式化文本
echo wpautop( $post_content );
答案 2 :(得分:0)
不太挑剔,但是我发现,如果我复制Wordpress帖子中“文本”区域中的所有内容,然后将其粘贴到markdown的HTML编辑器中,则会导致
标签被添加WordPress忽略它们的任何地方!