Created
September 25, 2015 15:50
-
-
Save abrudtkuhl/8c66c59791f42ad45423 to your computer and use it in GitHub Desktop.
WordPress Single Page Template For Categories
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
<?php | |
// CATEGORY SINGLE TEMPLATES :: single-{category_slug}.php | |
add_filter( 'single_template', | |
create_function( '$t', 'foreach( (array) get_the_category() as $cat ) { | |
if ( file_exists(TEMPLATEPATH . "/single-{$cat->slug}.php") ) return TEMPLATEPATH . "/single-{$cat->slug}.php"; | |
} return $t;' ) ); | |
// Example | |
// single-news.php |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Andy,
Thank you for the code.
It's almost exactly what I was looking for.
A note: using TEMPLATEPATH won't work if using a child template.
This will look in the parent template directory for the single-{cat->cslug}.php file.
I replaced it with dirname(FILE) to fix this.
Thanks again,
C