Created
January 9, 2015 02:41
-
-
Save DevelopKim/a11d7c9ae83b344b3364 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 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
/** | |
* 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