And created a template called "single-31.php" and placed it in the same directory as single.php (31 being the id number of the category I want to apply the different template to).
I have created a post with only that category applied to it.
Unfortunately nothing is happening and it is still using the default single.php template.
The opening <?php and closing ?> are already in your functions.php file, so you shouldn't be adding them. functions.php is not a template file like the other theme files, so you don't want it to be printing, as it will do with that code.
Also, be sure that all that actually is on one line; if you break it up onto multiple lines, it has to be done correctly or else it won't work.
Wordpress version: 2.7
Theme: Kubrick, default
Hi
I tried implementing your Wordpress, single post, template code suggested to Nathan Rice,
http://www.nathanrice.net/blog/wordpress-single-post-templates/
I have added this line to my functions.php
<?php add_filter('single_template', create_function('$t', 'foreach( (array) get_the_category() as $cat ) { if ( file_exists(TEMPLATEPATH . "/single-{$cat->term_id}.php") ) return TEMPLATEPATH . "/single-{$cat->term_id}.php"; } return $t;' ));?>
And created a template called "single-31.php" and placed it in the same directory as single.php (31 being the id number of the category I want to apply the different template to).
I have created a post with only that category applied to it.
Unfortunately nothing is happening and it is still using the default single.php template.
Can anyone help?
Thanks very much
The opening
<?phpand closing?>are already in yourfunctions.phpfile, so you shouldn't be adding them.functions.phpis not a template file like the other theme files, so you don't want it to be printing, as it will do with that code.Also, be sure that all that actually is on one line; if you break it up onto multiple lines, it has to be done correctly or else it won't work.
RSS feed for this topic
Reply
You must log in to post.