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

$query = new   
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();?>
<?php //the_title();?>
<?php endwhile;

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.


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();?>
                    <?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

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>";

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.