• Hi, I wondering if it’s possible to tell WordPress i’d like posts of one type to open in a different template to all the others? Forgive if this has been asked already! It’s for a portfolio page, I could really do with these pages being styled differently to normal posts out of my blog sidebar….

    Many thanks, Dan

Viewing 4 replies - 1 through 4 (of 4 total)
  • Here is the principle. You must apply it to your specific situation.

    Unique Single template
    Suppose you want to use different Single template to display individual post in certain category. You can use the in_category to check what category is the post stored in and then use different Single template. In your default single.php, enter the code below. If the post is in category 1, use single1.php, elseif in category 2, use single2.php, otherwise use single_other.php.
    <?php $post = $wp_query->post;
    if ( in_category(‘1’) ) {
    include(TEMPLATEPATH . ‘/single1.php’);
    } elseif ( in_category(‘2’) ) {
    include(TEMPLATEPATH . ‘/single2.php’);
    } else {
    include(TEMPLATEPATH . ‘/single_other.php’);
    } ?>
    1) You must use category ID codes that exist on your site
    2) In the code example, single_other.php becomes the default sidebar.
    3) To set this up, rename your theme’s file single.php to the name of the new default file – in the example that is single_other.php (use whatever name you prefer).
    4) Make a new file in your theme folder called single.php – paste the code I posted in that new file. that is the only thing that should be in the new single.php.
    5) Make new files single1.php, single2.php, single3.php, setting them up however you wish as custom single templates.
    Give them whatever file name you want. Just change the name of the file for that category in the IF statement I posted to match the actual filename you give the file.

    Thread Starter g3legacy

    (@g3legacy)

    Hi, thanks for the message – would that code go in functions.php or the file where i’m making my portfolio query (portfolio.php for example)?

    The code completely replaces the contents of single.php You move what is currently in single.php into a file, say, single-default.php

    if ( in_category('1') ) {
    include(TEMPLATEPATH . '/single1.php');
    } elseif ( in_category('2') ) {
    include(TEMPLATEPATH . '/single2.php');
    } else {
    include(TEMPLATEPATH . '/single_default.php');
    } ?>

    If none of your specific conditions are met, the regular single_default.php template will be used.

    Thread Starter g3legacy

    (@g3legacy)

    Ah, great that makes a lot sense – your just routing the categories down a different path. I will give this a shot, thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘the use of single.php….’ is closed to new replies.