[英]wordpress missing P tag
I am creating a file outside of wordpress but i want to get wordpress post etc. I created the following which does whar i want it to do but it is missing th P
tags. 我正在wordpress之外创建文件,但我想获取wordpress发布等信息。我创建了以下代码,虽然我想这样做,但缺少
P
标签。 if i view this post through wp-admin it looks fine. 如果我通过wp-admin查看此帖子,它看起来很好。 if i view it through this function it doe snot look find
如果我通过此功能查看它,不会发现
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;
post_content
won't show proper formatting...basically ever. post_content
基本上不会显示正确的格式。 You need to apply the_content
filter to it: 您需要对其应用
the_content
过滤器:
echo apply_filters('the_content', $data);
Here's where it's mentioned in the Codex . 这是食典中提到的地方。
While wpautop
will only add paragraph tags where new lines exist, the_content
runs a bunch of core filters (including wpautop
). 虽然
wpautop
将仅在存在新行的地方添加段落标签, the_content
运行了一堆核心过滤器(包括wpautop
)。 From the source , the_content
includes: 从源头来看,
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' );
您还可以使用wpauto
,它在wordpress中用于自动格式化文本
echo wpautop( $post_content );
Not very techy, but I found that if I copy everything from the "text" area in a Wordpress post, then paste it into a markdown to HTML editor, then it results in 不太挑剔,但是我发现,如果我复制Wordpress帖子中“文本”区域中的所有内容,然后将其粘贴到markdown的HTML编辑器中,则会导致
tags being added wherever Wordpress omits them! WordPress忽略它们的地方添加的标签!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.