• Hi everyone,

    I have a question about the page “single.php”. I would like to place a different templace depending the category I want to read.

    For example, I have these two categories (Sports) & (Hunting).

    So that it.. When I’m browsing the category Sports on the Sports page (my template is working) and I want to read [x] post and I press “Read more”, I fall on the “Hunt” template because the Hunt template is the default one.

    I discovered that I can place something like this

    get_header(‘sports’) to get my sports template via. CSS but How can I call it on the permalink I’m browsing?

    Any ideas someone?

    *Add tags if you don’t know the answer but you might think of a good tag 🙂

Viewing 5 replies - 1 through 5 (of 5 total)
  • I think that you could use conditional tags for this
    put this code in header.php below
    <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
    CODE:

    <?php if (is_category('sports') || in_category('sports')) { ?>
    <link rel="stylesheet" href="<?php bloginfo('stylesheet_directory'); ?>/sports.css" type="text/css" media="screen" />
    <?php } elseif (is_category('hunting') || in_category('hunting')) { ?>
    <link rel="stylesheet" href="<?php bloginfo('stylesheet_directory'); ?>/hunting.css" type="text/css" media="screen" />
    <?php } ?>

    Thread Starter Patrice Poliquin

    (@poliquinp)

    I’ll try this! I get you an anwser soon 🙂

    Thread Starter Patrice Poliquin

    (@poliquinp)

    I’m now a bit confused about your code,

    How it can detect that I cliked on “read more” in the page “sports” ?

    I was also using diffrent templates… for exemple.. the page hunting is

    /*
       Template name: Page hunting
    */

    and the page template for sports is actually

    /*
       Template name: Page sports
    */

    I just called a different header.. with a new css 🙂

    Your code sounds to be working but do I need to call the category somewhere?

    well you were talking about single.php not about custom-page.php where we could use

    /*
       Template name: Page sports
    */

    single.php is for posts not for pages so your code above will not work on posts when you go to post page.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Get a different template for the post’ is closed to new replies.