WordPress.org

Ready to get started?Download WordPress

Forums

[closed] Get a different template for the post (6 posts)

  1. poliquinp
    Member
    Posted 4 years ago #

    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 :)

  2. admark
    Member
    Posted 4 years ago #

    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 } ?>
  3. poliquinp
    Member
    Posted 4 years ago #

    I'll try this! I get you an anwser soon :)

  4. poliquinp
    Member
    Posted 4 years ago #

    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?

  5. admark
    Member
    Posted 4 years ago #

    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.

  6. esmi
    Forum Moderator
    Posted 4 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic