Skip to content

Instantly share code, notes, and snippets.

@ChaseWiseman
Created September 30, 2017 02:15
Show Gist options
  • Save ChaseWiseman/084133972d9d10d0df85c196589b0aab to your computer and use it in GitHub Desktop.
Save ChaseWiseman/084133972d9d10d0df85c196589b0aab to your computer and use it in GitHub Desktop.
Subcategory madness
<?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