-
-
Save billerickson/ced97b647de07ca9436bf1c741b4bf27 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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