Support » Themes and Templates » Want to create a very simple page template

  • I want to create a very simple page template that I can use for one of my pages. I want it to work/act/look just like the default template that my theme uses, except it will specify a special .css file to use.

    But how do I go about this?
    I’m looking at the other template files for examples, but those templates all replace the pages content with other specific data, so that’s not helpful. There are few relatively simple examples that show me that I’ll need to run the function get_header() at the start and get_footer() at the bottom, but since they also override the content I could add into the page itself, I don’t know what I’d need to keep that content.
    I’m looking at the tutorials and info in the codex, but I have failed to find a really basic example that shows me how to make a simple template.

    What would be the most basic template that just extends the default template but does nothing? And where would I need to plug in the command to use a different .css file?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Does your theme’s header.php use the body_class() function?

    Thread Starter Marscaleb

    (@marscaleb)

    Yes.

    <?php wp_head(); ?>
    </head>
    <body <?php body_class(); ?>>
    <?php

    I see it right there.

    Then you can use the classes generated by the body_class() function to target your new CSS on the new page only – with the added benefit that you can out this all in the main stylesheet – this avoiding a costly call to a second stylesheet.

    For example:

    body.page-id-174 #wrapper {background:#c00;}

    would turn the entire wrapper div red on the page with the id of 174 only. None of the other pages would be affected.

    Thread Starter Marscaleb

    (@marscaleb)

    So in other words I would be adding all of the changes I wanted to my main stylesheet and just making sure they only effect this one page?

    Well one of the reasons I want a page which uses a different .css file is because I’m adding a large list of custom classes/id’s that will not be used on other pages. If I add all this to the main .css file then every page will need to load and process that info. It may not exactly be enough to truly impact the performance of the site, but it seems like such a terrible waste. It seems to me that it is more sensible to add a “costly call” to one single page than to increase the tax on every single page, post, and blog on my site.

    Besides, don’t most browsers download the stylesheet again for each page they visit on the site? When I make a change to my stylesheet I can see the changes by moving to another post instead of hitting the refresh button. It seems a bit wasteful to add an extra 3,000 characters of text to each and every page-view when those lines are only needed by a page most people won’t visit. If twenty people read through twenty pages of archives, that’s an extra half-meg of download. Not exactly something to cry about, but still…

    So in other words I would be adding all of the changes I wanted to my main stylesheet and just making sure they only effect this one page?

    Correct.

    If I add all this to the main .css file then every page will need to load and process that info.

    That’s still far less “expensive” than another HTTP call to a second .css file.

    don’t most browsers download the stylesheet again for each page they visit on the site?

    No. The stylesheet is loaded once and then cached for subsequent pages.

    Thread Starter Marscaleb

    (@marscaleb)

    No. The stylesheet is loaded once and then cached for subsequent pages.

    Then why can I make a change to my stylesheet, load a new page, and see the changes? Whereas if I changed an image file I can go to a new page, come back, and it still shows that same file until I hit refresh.

    You’ve configured your browser not to cache stylesheets? But I can assure you that 1 big stylesheet is better in terms of page load & performance than 2 or 3 separate sheets. Why do you think Twenty Eleven even loads the print css in the main stylesheet? It’s to avoid another http call.

    Thread Starter Marscaleb

    (@marscaleb)

    Well if you say so, I’ll just have to take your word at it. It still sounds silly; this is for my links page and I can’t imagine that I will get very many views on that page, especially compared to the actual content of my site.

    So for the parts that I want to alter, the context is universally body.page-id-(page name here)?
    So to alter my links page it would be body.page-id-links #Part_To_Alter ?

    (Forgive me if I read that wrong, still new to php and css)

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Want to create a very simple page template’ is closed to new replies.