Support » Fixing WordPress » could use some help with page template

  • David

    (@thatseoguydavid)


    hello,
    my site is http://thatwebguydavid.com, I am trying to create a squeeze page using a template file.

    Thats the easy part, now I want to add a conditional comment to my header.php that tells it to not display the navigation and rss area at the top.

    I have 2 questions, is this the best way to go about it and if so what would be the conditional comment 🙂

    Would it be better to just have my template call a different header.php and if so how would I go about doing that.

    Any help is greatly appreciated.

Viewing 15 replies - 1 through 15 (of 18 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    moderator

    You can use conditional Conditional_Tags in your template files.

    like so:

    <?php
    if (is_home()) {
    // do stuff
    } else {
    // do stuff
    }
    ?>

    A conditional tag would work for that, so there would be no need to pull in a second header.

    If it’s the home page, you could use this to suppress the code on the home page:

    <?php if (!is_home()) {?>
    
     Insert your code...
    
    <?php }?>

    You can find more info here: http://codex.wordpress.org/Conditional_Tags

    David

    (@thatseoguydavid)

    I just read somewhere else that you can include the doc type and all that stuff right on the page template, so now Im wondering if I can avoid calling in any other files and style with inline css, what do you guys think of that?

    I do that on a couple templates which I want totally separate from the rest of my site, but still managed by WP. Just copy everything from the DOCTYPE (1st line in header.php) through </head> and paste in right under the page template header

    that’s all the business that keeps wordpress runnning. Just remember to include the <body> after the </head> in your new template, and close everything at the bottom with the </body> and </html>

    Moderator keesiemeijer

    (@keesiemeijer)

    moderator

    Then you have to include it on every other template file as well. And whenever you want to change anything in the header you have to do this on every other template file as well. It’s not really a smart thing to do. Same with the inline css.

    I’m with @keesiemeijer on that one.

    It would be much easier to create a new page template that calls in a second header.

    To do that, create a new header file (just copy everything from you’re current header) and call that new file header-header2.php

    Then do the same with your page template–create a second one. You can call that file whatever you want.

    At the top of that template, put this code:

    <?php
    /*
    Template Name: New Template Name
    */
    ?>
    
    <?php get_header('header2'); ?>

    And now you’ll have a new page template that pulls in a different header.

    You can edit header-header2.php all you want.

    David

    (@thatseoguydavid)

    Ok food for thought thanks for all your responses very very helpful thankful.

    I don’t see the point in creating a new header….. for a single page template.

    BUt it can be done yes. I guess if you plan to make more than one template with the modified header, it would definitely make sense.

    either way… chacun son gout I guess! 😉

    David

    (@thatseoguydavid)

    After thinking about it a bit you do need to use the get the header if your using Google Analytics, right?

    nope…. not necessarily. Depends if your theme/plugin inserts it in the header or footer

    But on your template you can include the calls to wp_head and wp_footer that are normally part of header.php and footer.php

    Those are the bits of code required by plugins

    If you have analytics code hard coded into footer.php, it can be included in the template as well

    It does look like the yoast analytics plugin that you’re using does put it in the header though.

    David

    (@thatseoguydavid)

    yeah mine is in the header, im gonna call the header the way you (Alx) mentioned and just strip everything I don’t want out of it. You guys are awesome btw 🙂

    David

    (@thatseoguydavid)

    I set up my page template to call the new header2.php and I removed the nav div from my header2.php but when I view the page the nav is still there, I dont get it. it seems like it’s defaulting back to header.php

    Can you plop the header2.php and the new page template code into the pastebin and post the URL?

    David

    (@thatseoguydavid)

    I cant get paste bin to work 🙁

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘could use some help with page template’ is closed to new replies.