如何使用特定的template.php遍历页面

时间:2014-12-31 12:41:00

标签: php wordpress loops

我想知道如何循环浏览Wordpress中具有特定模板的页面。我有一个模板sale.php,该模板已分配给某些pages(不是帖子)。我想做以下事情:

  <div class="test">
    <?php $recent = new WP_Query("template_name=sale"); while($recent->have_posts()) : $recent->the_post();?>
        <?php the_title(); ?>
        <?php the_content(); ?>
    <?php endwhile; ?>
  </div>

显然template_name=sale无效。有什么我可以作为查询的参数,只获取具有特定模板的所有页面的内容。

由于

1 个答案:

答案 0 :(得分:0)

您可以使用此行代码循环使用特定模板的页面

<?php is_page_template( $template ); ?>我的意思是

if ( is_page_template( 'sale.php' ) ) {
while (have_posts()) : the_post();
the_content();
endwhile;
 }  
 ?>

我希望这段代码适合你