Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save DevelopKim/a11d7c9ae83b344b3364 to your computer and use it in GitHub Desktop.
Save DevelopKim/a11d7c9ae83b344b3364 to your computer and use it in GitHub Desktop.
/**
* Load different template for sub category
*/
function sub_category_template() {
// Get the category id from global query variables
$cat = get_query_var('cat');
if(!empty($cat)) {
// Get the detailed category object
$category = get_category($cat);
// Check if it is sub-category and having a parent, also check if the template file exists
if( ($category->parent != '0') && (file_exists(TEMPLATEPATH . '/sub-category-template.php')) ) {
// Include the template for sub-catgeory
include(TEMPLATEPATH . '/sub-category-template.php');
exit;
}
return;
}
return;
}
add_action('template_redirect', 'sub_category_template');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment