ThemeShaper Forums » Thematic


using different layouts for different templates

(8 posts)
  • Started 11 years ago by jamis
  • Latest reply from helgatheviking
  • This topic is not resolved
  1. jamis

    I'm building a site that uses the layout "2c-l-fixed.css" on most of the pages, but for a few pages I need a 3-column layout and I'd like to use the layout "3c-fixed.css" as the basis for my new template. But for the life of me I can't figure out how to make a layout apply to only a single template, rather than applying to every page in a site.

    Thanks in advance!

    Posted 11 years ago #
  2. Quick and dirty here. You'll want to take a look at the wordpress conditional tags codex to format the if statement to suit your needs, but this should give you a general idea of how to shove a stylesheet on a per-template basis.

    //add custom stylesheet 
    	function custom_layout() {
    		if (is_page()) {?>
    	   	 	<link rel="stylesheet" type="text/css" href="<?php echo bloginfo('stylesheet_directory') ?>/custom_layout.css" /> <?php }
    	add_action('wp_head', 'custom_layout');
    Posted 11 years ago #
  3. jamis

    Thanks for your quick reply.

    Please excuse my lack of knowledge, I'm wondering if I can impose on your generosity with a couple of questions. I come at this as someone who is comfortable with HTML and CSS but pretty clueless in PHP.

    I'm recreating an existing site, and I'm using pages to do it. I'm thinking that I can duplicate "page.php" and call it "page-3c.php"

    Then I edit that new file, adding the code you provided, after the tag <?php at the top of the page, and before the code:

    // calling the header.php

    Am I anywhere near the ballpark with that?

    But I'm equally baffled at how I specify which pages use "page.php" and which pages use "page-3c.php"

    I apologize for being in over my head.

    Posted 11 years ago #
  4. well....close, cigar my friend.

    The code I posted above is to be entered into your functions.php, located within your childtheme's main directory.

    You are right on the money regarding page templates, you could take page.php and do with it as you will, HOWEVER, from what you've written, my advice is to slow down a little, put your reading glasses on, and read the following:

    then read:

    These two articles arn't terribley "code heavy", and will make your life MUCH easier at the stage in the game you are in.

    Once you've built this foundation, seriously, in your spare time, read EVERYTHING Ian has written on his blog. I can't tell you how many times I return back to his basic thematic customization guide, it seems so...brief, until you start to get how thematic does things, then you'll see that his guide is just chock full of goodness.

    Posted 11 years ago #
  5. jamis

    Thanks again for your timely help. And thanks for pointing me to the "How to Modify WP Themes the Smart Way" article. The articles on Filter Hooks and Action Hooks helped a lot.

    I've got 10 or so pages on the site that need a different layout. When I use your code and insert a single number after (is_page( everything works fine, like this with page 107:

    if (is_page(107)) {?>

    But when I try to insert multiple numbers:

    if (is_page(107,109)) {?>

    . . . nothing works. I've tried using spaces after the commas (107, 109) and I've tried using only spaces and no commas (107 109) but neither seems to do the trick.

    Do I need to repeat the entire chunk of code you provided in your first posting 10 times, once for each page that gets the different stylesheet? That seems kludgy.

    Posted 11 years ago #
  6. jamis

    Yet another question: when I look at the page in Firebug I notice in the <head> that there's a link for the original stylesheet, and further down there's also a link for the new stylesheet. Does that sound right?

    Thanks so much!

    Posted 11 years ago #
  7. ok, to your first issue, you can do:

    if (is_page(1) || (is_page(2) || (is_page(3)) {?>

    But go read the Wordpress Codex on conditional Tags, this will help you design the code more efficiently.

    they way we're doing this, yes, you are loading the default style.css first, then for our custom pages you are adding a second stylesheet to override the first.

    There are a couple ways of doing this, this method is arguably NOT the most efficient (but is one of the easiest and most straightforward, but if your site isn't receiving 10,000 visitors a day, the performance hit is insignificant.

    You could just add template specific CSS to style.css, such as

    page-template-yourpage body {color:#ffffff;}

    but as a site grows, in my opinion things get unwieldy, and its better long term to keep stylesheets (and other things) compartmentalized for easy maintenance.

    Posted 11 years ago #
  8. chris' article seems like exactly what you are looking for

    and where he has:
    if (is_home() || is_front_page()) {

    you will need to insert your own conditional logic.

    as for your q about multiple pages you need to call them in array format... see the codex

    is_page(array(42,'about-me','About Me And Joe'))

    Posted 11 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.