• Hi, I’m trying to test out having different templates for different single posts in each category. Following this advice, I made different templates named single-#.php, etc. and inserted this code into single.php:

    <?php post;
    
    if ( in_category('190') ) {
    include(TEMPLATEPATH . '/single-190.php'); }
    
    elseif ( in_category('191') ) {
    include(TEMPLATEPATH . '/single-191.php'); }
    
    else { include(TEMPLATEPATH . '/single.php'); } ?>

    However when I use that, all the Uncategorized single posts get a 500 error. When I use the original code

    <?php post;
    
    if ( in_category('190') ) {
    include(TEMPLATEPATH . '/single-190.php'); }
    
    elseif ( in_category('191') ) {
    include(TEMPLATEPATH . '/single-191.php'); }
    
    else { include(TEMPLATEPATH . '/single_default.php'); } ?>

    the post shows up but I also get the following error:

    Warning: include(/home/accountname/domain.com/wp-content/themes/sandbox/single_default.php) [function.include]: failed to open stream: No such file or directory in /home/accountname/domain.com/wp-content/themes/sandbox/single.php on line 11

    Warning: include() [function.include]: Failed opening ‘/home/accountname/domain.com/wp-content/themes/sandbox/single_default.php’ for inclusion (include_path=’.:/usr/local/php5/lib/php:/usr/local/lib/php’) in /home/accountname/domain.com/wp-content/themes/sandbox/single.php on line 11

    Any advice?

The topic ‘Different templates for different category posts’ is closed to new replies.