// remove the stock filter
remove_filter('single_template','gpp_single_template');
// add the new one
add_filter('single_template', 'single_template_override');
//add single post template depending on category slug
function single_template_override($path) {
global $wp_query, $post;
$categories = get_the_category();
$cat_slugs = array();
foreach ($categories as $cat) {
$cat_slugs[] = $cat->slug;
}
$templates = array();
// add in the top priorities if present
if (in_array('fine-art', $cat_slugs)) {
// add to the beginning
array_unshift($templates,$templates[] = 'single-fine-art.php');php';
}
foreach($cat_slugs as $cat_slug) :
// single posts template based on category slug
$filename = 'single-' . $cat_slug . '.php';
// if not already in the array, add it
if (!in_array($filename, $templates)) {
$templates[] = $filename;
}
endforeach;
$found = locate_template($templates, false);
if ($found) {
return $found;
} else {
return $path;
}
}
edited the line below `// add to the beginning`. using `array_unshift` on an empty array could've caused a problem, but it still isn't working.
Evan Mattson
- 956
- 1
- 10
- 20