0

I'm working on a sub-directory site of a multisite (e.g. mainsite.domain.com/sub-directory-site). On the main site, I have set up a system where users create posts and depending on what category they are assigned they get different template files (e.g. 'single-11.php' where 11 is the tag_id matching a category).

My problem is that I want to use this same system for the sub-directory-site, but when I try to do this the sub-directory-site post pages don't load their respective 'single-*.php' file. They don't even appear to load the 'single.php' file. All of these files are located within the same theme folder (e.g. .../themes/twentyten/single-11.php).

Currently my mainsite's single post templates are loaded by use of a filter in the functions.php file. It's roughly the following code:

//Gets post cat slug and looks for single-[cat slug].php and applies it
add_filter('single_template', create_function(
'$the_template',
'foreach( (array) get_the_category() as $cat ) {
if ( file_exists(TEMPLATEPATH . "/single-{$cat->slug}.php") )
return TEMPLATEPATH . "/single-{$cat->slug}.php"; }
return $the_template;' )
);

I've searched all over the internet and the WP codex pages and no one seems to have addressed this issue. Either I'm going about this all wrong (probably the case) or I'm not searching properly. Any advice either way would be immensely helpful.

0

Use STYLESHEETPATH instead of TEMPLATEPATH. You'll find the definitions in wp-includes/default-constants.php file. Please have look. So your code block will be like below-

//Gets post cat slug and looks for single-[cat slug].php and applies it
add_filter('single_template', create_function(
        '$the_template',
        'foreach( (array) get_the_category() as $cat ) {
            if ( file_exists(STYLESHEETPATH . "/single-{$cat->slug}.php") )
            return STYLESHEETPATH . "/single-{$cat->slug}.php"; 
         }
         return $the_template;' 
    )
);

Hope that helps you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.