Last active
July 19, 2019 17:44
-
-
Save stefanpejcic/e2c4b0d97bf0d65c41991027002d430b to your computer and use it in GitHub Desktop.
Different single post template based on category
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
define(SINGLE_PATH, TEMPLATEPATH . '/single'); | |
add_filter('single_template', 'my_single_template'); | |
function my_single_template($single) { | |
global $wp_query, $post; | |
foreach((array)get_the_category() as $cat) : | |
if(file_exists(SINGLE_PATH . '/single-cat-' . $cat->slug . '.php')) | |
return SINGLE_PATH . '/single-cat-' . $cat->slug . '.php'; | |
elseif(file_exists(SINGLE_PATH . '/single-cat-' . $cat->term_id . '.php')) | |
return SINGLE_PATH . '/single-cat-' . $cat->term_id . '.php'; | |
endforeach; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment