Skip to content

Instantly share code, notes, and snippets.

@cliftoncanady
Created July 5, 2014 20:56
Show Gist options
  • Save cliftoncanady/0c6dba794da6ddfd538e to your computer and use it in GitHub Desktop.
Save cliftoncanady/0c6dba794da6ddfd538e to your computer and use it in GitHub Desktop.
WP SNIPPET: OnePage wp_query
<?php
global $wp_query;
// is Page a parent page
if ( $post->post_parent == 0 ) {
// on a parent page, get child pages
$pages = get_pages( 'hierarchical=0&parent=' . $post->ID );
// loop through child pages
foreach ( $pages as $post ){
setup_postdata( $post );
// get the template name for the child page
$template_name = get_post_meta( $post->ID, '_wp_page_template', true );
$template_name = ( 'default' == $template_name ) ? 'page.php' : $template_name;
// default page template_part content-page.php
$slug = 'page';
// check if the slug exists for the child page
if ( locate_template( basename( $template_name ) , $load, $require_once ) != '' ) {
$slug = pathinfo( $template_name, PATHINFO_FILENAME );
}
// load the content template for the child page
get_template_part( $slug );
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment