Single Post Category Template
-
I want to change the single post page depending on the category. I was trying to use the plugin found here…
https://boren.nu/archives/2005/03/13/custom-post-templates-plugin/
but for some reason I can’t get it to work.
Here is my version of the plugin… anybody see anything wrong with this.. I just drop the template in the same folder as the rest of the theme files right?
<?php
/*
Plugin Name: Custom Post Templates
Plugin URI: https://boren.nu/
Description: Load custom single post templates.
Author: Ryan Boren
Version: 0.9
Author URI: https://boren.nu/
*/function cpt_custom_post_template($template) {
global $wp_query;$post = $wp_query->post;
$id = $post->ID;// If a template exists for this post ID, load it.
if ( file_exists(TEMPLATEPATH . “/single-{$id}.php”) )
return TEMPLATEPATH . “/single-{$id}.php”;// Add custom checks here. For example, give posts different templates
// depending on what categories they are in.
if ( in_category(’15’) && file_exists(TEMPLATEPATH . “/single-cat-15.php”) )
return TEMPLATEPATH . ‘/single-cat-15.php’;if ( in_category(’16’) && file_exists(TEMPLATEPATH . “/single-cat-16.php”) )
return TEMPLATEPATH . ‘/single-cat-16.php’;return $template;
}add_filter(‘single_template’, ‘cpt_custom_post_template’);
?>Any help would be greatly appreciated.
Thanks
- The topic ‘Single Post Category Template’ is closed to new replies.