Forums

How to create a page template that uses a different style.css? (15 posts)

  1. Mandarke
    Member
    Posted 3 years ago #

    Please forgive me if I am being horribly ignorant, or have missed an obvious section of the tutorial, but I wish to create a page template that uses a slightly different style sheet than the default style.css and I don't know where to begin? I'm using the K2 theme and I need to create a page template that uses different fonts than the default K2 fonts. The style sheet seems to control everything to do with fonts and the page.php is quite short - am I to assume that the page.php simply calls instructions from the style.css and if so how do I get to call a different set? Any words of advice will be met with the warmest of appreciative sentiments.

  2. miniimage
    Member
    Posted 3 years ago #

    create another stylesheet
    and call for that stylesheet
    using the link rel

  3. Mandarke
    Member
    Posted 3 years ago #

    thanks - though what is 'the link rel'? What might that look like in the page.php file? chars!

  4. miniimage
    Member
    Posted 3 years ago #

    wait let me look at the k2 template

  5. miniimage
    Member
    Posted 3 years ago #

    ok so i think i've got it

    1. go to your page.php
    2. erase <?php get_header(); ?>
    3. go to your header.php
    4. select all and copy everything
    5. go back to the page.php
    6. paste everything at the top, which replaces the <?php get_header(); ?>
    7. create a new stylesheet
    8. once you are done save the stylesheet as pagestyle.css
    9. go back to the page.php
    10. find <link rel="stylesheet" type="text/css" media="screen" href="<?php echo get_template_directory_uri(); ?>/style.css" />
    11. and change that to <link rel="stylesheet" type="text/css" media="screen" href="<?php echo get_template_directory_uri(); ?>/pagestyle.css" />

    oh and ignore the numbers its messed

    just follow the order from top to bottom

  6. miniimage
    Member
    Posted 3 years ago #

    guys tell me if i'm right

    i'm actually pretty new to wordpress (i started since october 11)

  7. Len
    Member
    Posted 3 years ago #

    You could also do this:

    Look in header.php for the call to the style sheet. It will look something like this...

    <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />

    We just need to wrap a few lines of code around it. Let's assume the numerical ID of the page in question is 50.

    <?php if ( is_page('50') ) { ?>
    <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/pg-50.css" type="text/css" media="screen" />
    <?php } else { ?>
    <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>"  type="text/css" media="screen" />
    <?php } ?>

    What this says is if we are on the page with the ID of 50 use the style sheet pg-50.css and if not then use the regular style sheet. By the way you can also style categories this way. Rather than using is_page you would use is_category

  8. Mandarke
    Member
    Posted 3 years ago #

    This advice is absoloutely golden guys - can I just ask from a conceptual point of view why I would be editing the header.php rather than the page.php if I am concerned with editing the fonts of pages? Many thanks once again!

  9. miniimage
    Member
    Posted 3 years ago #

    Because in the page.php it calls for the header.php with this code:

    <?php get_header(); ?>
  10. Mandarke
    Member
    Posted 3 years ago #

    You are all wonderful humans

  11. pusbucket
    Member
    Posted 3 years ago #

    This is great but I'm having trouble adding a 3rd call:

    <?php if ( is_page('50') ) { ?>
    <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/pg-50.css" type="text/css" media="screen" />
    <?php elseif ( is_page('51') ) { ?>
    <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/pg-51.css" type="text/css" media="screen" />
    <?php } else { ?>
    <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>"  type="text/css" media="screen" />
    <?php } ?>

    this kills everything and I'm given a blank page (no error report)
    What'd I do?

  12. Len
    Member
    Posted 3 years ago #

    You're on the right track but you have a slight syntax error on one line although I'm surprised it didn't throw an error message. Your missing a "}" on line 3 of the code you posted.

    <?php elseif ( is_page('51') ) { ?>

    Should read...

    <?php } elseif ( is_page('51') ) { ?>

  13. pusbucket
    Member
    Posted 3 years ago #

    WOOPS!
    thanks LenK!!!

  14. paintersinn
    Member
    Posted 3 years ago #

    My goodness you are all genius, well done and thank you, you have saved me from insanity x

  15. misterwendellcat
    Member
    Posted 3 years ago #

    Great advice!
    Can I have someone look at my call and see what I'm missing? I'm trying to have style.css called for the homepage and style2.css for everything else but I can't seem to get it past the first stylesheet. Whichever stylesheet I call in the first "if" line will cover the whole site. (I have a front page and 4 "static" pages in the navigation and I'm using a page.php template).

    I must be missing something simple here? I've tried several different alterations of the code I've found in the forums to no effect.

    [code]
    <?php if (is_front_page) { ?>
    <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/style.css" type="text/css" media="screen" />
    <?php } else { ?>
    <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/style2.css" type="text/css" media="screen" />
    <?php } ?>
    [/code]

    Cheers!
    Steve

Topic Closed

This topic has been closed to new replies.

About this Topic