Skip to content

Instantly share code, notes, and snippets.

@daronspence
Created October 15, 2014 22:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daronspence/c3411fd1fc4f4951799b to your computer and use it in GitHub Desktop.
Save daronspence/c3411fd1fc4f4951799b to your computer and use it in GitHub Desktop.
<?php
$args = array(
// Get children of current page
'post_parent' => $post->ID,
'post_type' => 'page',
);
$query = new WP_Query($args);
if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();
$template = get_post_meta( $post->ID, '_wp_page_template', true );
// Template must have 1 dash. EG: "template-name.php"
$template = pathinfo($template);
$template_parts = explode('-', $template['filename']);
// use first 2 keys in array of $template_parts
get_template_part( $template_parts[0], $template_parts[1] );
endwhile; endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment