• I have been using this tutorial for creating post templates ready rather than having them selected in the admin with a plugin.

    However, i have run into a problem..

    My single.php has this code in..

    <?php
    if (in_category('1')) {include (TEMPLATEPATH . '/single-1.php');
    }
    if (in_category('3')) {include (TEMPLATEPATH . '/single-3.php');
    }
    else { include (TEMPLATEPATH . '/single-default.php');
    }
    ?>

    i.e if cat 1 show singe-1 if cat 3 show single-3 however, its not working properly, the single-1 is all messed up whilst the single-3 is fine.

    Is the code connected properly via php? If not how do i connect it so it does the job it should…

    Many thanks 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • It looks ok structurally. However, if you are on cat == 1 this code will load single-1 and single-3 or single-default. I’m not sure if that is what you want. A nagging voice in my skull is telling me you want something like…

    if (in_category('1')) {
      include (TEMPLATEPATH . '/single-1.php');
    } elseif (in_category('3')) {
      include (TEMPLATEPATH . '/single-3.php');
    } else {
      include (TEMPLATEPATH . '/single-default.php');
    }

    … but you know it is with voices. Can’t trust ’em.

    As for why your layout is broken, it probably has something to do with loading single-1 and single-default vs single-1 and single-3 vs. only single-3 vs. only single-default. I’m guessing you are getting tag mis-matches depending upon which files load.

    An URL would help if you’ve got one.

    Thread Starter jezthomp

    (@jezthomp)

    Thanks so much thats worked a treat 🙂

    And if i wanted to add more single’s would it work like this…?

    if (in_category('1')) {
      include (TEMPLATEPATH . '/single-1.php');
    } elseif (in_category('3')) {
      include (TEMPLATEPATH . '/single-3.php');
    } elseif (in_category('4')) {
      include (TEMPLATEPATH . '/single-4.php');
    } else {
      include (TEMPLATEPATH . '/single-default.php');
    }

    Yes. You can add as many elseif‘s as you want, but if you start to get a very long string of them you might try to think of a different approach.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Single Post Template Problem…?’ is closed to new replies.