<--更多-->;显示WordPress内容时被忽略

<--更多-->;显示WordPress内容时被忽略,wordpress,Wordpress,我正在尝试编写一个插件,它将获取页面id并返回页面预览。这是我的密码: function page_preview($atts,$pageid = null) { extract(shortcode_atts(array( "pageid" => '0' ), $atts)); $the_query = new WP_Query( 'page_id=' . $pageid . '' ); global $more; $more = 0; if ( $the_query->

我正在尝试编写一个插件,它将获取页面id并返回页面预览。这是我的密码:

function page_preview($atts,$pageid = null) {
extract(shortcode_atts(array(
"pageid" => '0'
), $atts));
$the_query = new WP_Query( 'page_id=' . $pageid . '' );
global $more;    
$more = 0;   
if ( $the_query->have_posts() ) {

while ( $the_query->have_posts() ) {
    $the_query->the_post();
    $title=get_the_title();
    $thumbnail=get_the_post_thumbnail( $pageid, 'preview' );
    $content=get_the_content();
}
} 
return '<div class="callout">' . 
'<h4>' . 
$title . 
'</h4>' . 
$thumbnail . 
$content . '<a href="' . 
get_the_permalink($pageid) . 
'">Continue reading</a></div>';
}
add_shortcode( 'pagepreview', 'page_preview' );

通常可以解决这个问题,但我的情况并非如此。有人知道我做错了什么吗?谢谢。

你得到了全部内容,因为

$content=获取内容();

未应用
内容()
过滤器,并且
$more=0
必须位于while循环中
$the\u query->the\u post();
之后的一行。将while循环更改为:

while ( $the_query->have_posts() ) {
    $the_query->the_post();
    $more=0;
    $title=get_the_title();
    $thumbnail=get_the_post_thumbnail( $pageid, 'preview' );
    $content = apply_filters( 'the_content', get_the_content() );
    $content = str_replace( ']]>', ']]&gt;', $content );
}

请参阅WordPress Codex上的和,了解我的来源。

谢谢。尝试过这个,但仍然不起作用;我将$more=0放在了所有地方,但没有成功…你从插件中得到了什么输出?你得到了帖子的全部内容吗(在more标签的上方和下方)或者别的什么?获取文章的完整输出,上面和下面。我已经更新了我的答案。这个短代码现在正在我的WordPress安装中。不幸的是,没有我的。当我看到你的答案时,我非常激动,但它仍然拒绝接受更多标签。代码位于
while ( $the_query->have_posts() ) {
    $the_query->the_post();
    $more=0;
    $title=get_the_title();
    $thumbnail=get_the_post_thumbnail( $pageid, 'preview' );
    $content = apply_filters( 'the_content', get_the_content() );
    $content = str_replace( ']]>', ']]&gt;', $content );
}