I would like to know how it is possible to loop through pages which have a particular template in WordPress. I have a template sale.php
which is assigned to some pages
(not posts). I want to do following:
<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>
obviously template_name=sale
is not working. Is there something I can give as argument for the query to get only contents of all pages with a particular template.
Thanks
You can use this line of code to loop through pages with particular template
<?php is_page_template( $template ); ?>
i meanand i hope this code will work for you