【问题标题】:How to loop through pages with particular template.php如何循环浏览具有特定 template.php 的页面
【发布时间】:2014-12-31 12:41:00
【问题描述】:

我想知道如何在 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 不起作用。有什么我可以作为查询的参数给出的,以仅获取具有特定模板的所有页面的内容。

谢谢

【问题讨论】:

    标签: php wordpress loops


    【解决方案1】:

    您可以使用这行代码循环浏览具有特定模板的页面

    &lt;?php is_page_template( $template ); ?&gt; 我的意思是

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

    我希望这段代码对你有用

    【讨论】:

    • 你能描述一下我的代码面临的问题吗
    猜你喜欢
    • 2010-09-10
    • 2019-11-19
    • 1970-01-01
    • 2011-05-14
    • 1970-01-01
    • 2020-12-13
    • 2015-04-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多