Created
September 30, 2017 02:15
-
-
Save ChaseWiseman/084133972d9d10d0df85c196589b0aab to your computer and use it in GitHub Desktop.
Subcategory madness
This file contains hidden or 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 // remove this if you don't need it | |
function riz_new_subcategory_hierarchy( $path ) { | |
$category = get_queried_object(); | |
$parent_id = $category->category_parent; | |
if ( 123456 != $parent_id ) { // Your category ID | |
return $path; | |
} | |
$templates = array(); | |
// Create replacement $templates array | |
$parent = get_category( $parent_id ); | |
// Current first | |
$templates[] = "category-{$category->slug}.php"; | |
$templates[] = "category-{$category->term_id}.php"; | |
// Parent second | |
$templates[] = "subcategory-{$parent->slug}.php"; | |
$templates[] = "subcategory-{$parent->term_id}.php"; | |
$templates[] = "category-{$parent->slug}.php"; | |
$templates[] = "category-{$parent->term_id}.php"; | |
$templates[] = 'category.php'; | |
return locate_template( $templates ); | |
} | |
add_filter( 'category_template', 'riz_new_subcategory_hierarchy' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment