Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created June 14, 2016 16:26
Show Gist options
  • Save billerickson/ced97b647de07ca9436bf1c741b4bf27 to your computer and use it in GitHub Desktop.
Save billerickson/ced97b647de07ca9436bf1c741b4bf27 to your computer and use it in GitHub Desktop.
<?php
/**
* Template Hierarchy
*
*/
function ea_template_hierarchy( $template ) {
if ( is_page() ) {
$ancestors = get_ancestors( get_the_ID(), 'page' );
$children = get_pages( array( 'child_of' => get_the_ID() ) );
// Product page has an ID of 25
if ( in_array( 25, $ancestors ) || 25 == get_the_ID() ) {
if ( !empty( $children ) ) {
$template = get_query_template( 'product-listing' );
} else {
$template = get_query_template( 'product' );
}
}
}
return $template;
}
add_filter( 'template_include', 'ea_template_hierarchy' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment