Forked from DevelopKim/Load different template for sub category.php
Created
July 20, 2016 10:14
-
-
Save yumyo/ca59e36bdd39e922781ea5fd94a07886 to your computer and use it in GitHub Desktop.
Load different template for sub category
from http://www.mindfiresolutions.com/How-to-use-different-template-for-subcategories-in-Wordpress-2277.php
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
/** | |
* 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