-1

I have a parent page that is listing out all of it's child pages. This is done using the below:

<?php   
$query = new   
WP_Query('post_type=page&post_parent=80&posts_per_page=-1&orderby=menu_order&order=ASC');
while ( $query->have_posts() ) : $query->the_post(); ?>   
<div class="col-sm-1" id="inside_team_list">
<a href="<?php echo get_permalink();?>">
 <?php the_post_thumbnail();?>
</a>
</div>
<?php //the_title();?>
<?php endwhile;
wp_reset_postdata();
?>

Some of the child pages have different templates. What I've been trying to figure out is if it is possible to add some css design tweaks to the list of child pages based on their page templates.

E.G:

if ( is_page_template('template1.php') ){ ?>
                        <div style=" border-top: 3px solid #000;">
                        <div class="col-lg-3"id="child_thumb">                                                          
                            <a href="<?php echo get_permalink();?>">
                                <div class="work_title"><?php echo the_title(); ?></div>
                                <?php the_post_thumbnail();?>
                            </a>                                            
                        </div>
                     </div>
                    <?php } else{ echo 'different'; }?>

The issue I keep running into is that the is_page_template function is only checking for the current page template, not the page templates of all the child pages.

Any help would be greatly appreciated.

  • are you putting the above E.G: code inside the loop above? – NickFMC Jan 29 '15 at 3:11
  • I believe you can use a meta query to get that from within the your loop to create your if statement. codex.wordpress.org/Class_Reference/WP_Meta_Query below is the key to query 'key' => '_wp_page_template', 'value' => 'my_template.php' – NickFMC Jan 29 '15 at 3:23
2

In your wp_query loop you'll want to check the page template of the current post object. You'll be able to set that to a string and use it however you want

Close to this:

while ( $query->have_posts() ) : $query->the_post(); 
if (is_page) {
  $pageTemplate = basename( get_page_template() );
  echo "<p class=\"" . $pageTemplate . "\">" . get_the_title() . "</p>";
}
endwhile;

Refer to the codex page for more info on the function

  • 3
    don't forget to use basename( get_page_template() ) unless you really want the full path. – Privateer Jan 29 '15 at 3:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.