使用The_content时,单页wordpress不应用模板

时间:2015-05-20 20:15:09

标签: php wordpress templates

我正在构建一个单页的WordPress模板。我创建了一个简单的循环,它可以拉出所有页面并在同一页面上连续显示每个页面。它显示每个页面的内容,但不适用于已附加到页面的模板。 这是循环...

        $args = array(
                'post_type' => 'page',
                'order' => 'ASC'
            );
            $the_query = new WP_Query( $args );         
        ?>
        <?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?> 

    <?php the_content(); ?>
        <?php endwhile; endif; ?>

1 个答案:

答案 0 :(得分:0)

当您使用the_content时,该函数将仅返回表中提交的post_content的值。所以代码按预期工作。

尝试以下

if ( have_posts() ){
    while ( $the_query->have_posts() ) {
        $the_query->the_post();
        locate_template( get_template_slug( $post->ID ) )
    }
}

此代码使用locate_template函数查找模板文件,使用get_template_slug获取与每个页面关联的模板名称。

如果这有帮助,请告诉我。

相关问题