我正在构建一个单页的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; ?>
答案 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获取与每个页面关联的模板名称。
如果这有帮助,请告诉我。