WordPress.org

Ready to get started?Download WordPress

Forums

could use some help with page template (19 posts)

  1. David
    Member
    Posted 3 years ago #

    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.

  2. keesiemeijer
    moderator
    Posted 3 years ago #

    You can use conditional Conditional_Tags in your template files.

    like so:

    <?php
    if (is_home()) {
    // do stuff
    } else {
    // do stuff
    }
    ?>
  3. Alx Block
    Member
    Posted 3 years ago #

    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

  4. David
    Member
    Posted 3 years ago #

    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?

  5. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    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>

  6. keesiemeijer
    moderator
    Posted 3 years ago #

    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.

  7. Alx Block
    Member
    Posted 3 years ago #

    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.

  8. David
    Member
    Posted 3 years ago #

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

  9. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    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! ;)

  10. David
    Member
    Posted 3 years ago #

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

  11. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    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

  12. Alx Block
    Member
    Posted 3 years ago #

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

  13. David
    Member
    Posted 3 years ago #

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

  14. David
    Member
    Posted 3 years ago #

    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

  15. Alx Block
    Member
    Posted 3 years ago #

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

  16. David
    Member
    Posted 3 years ago #

    I cant get paste bin to work :(

  17. David
    Member
    Posted 3 years ago #

    Ok here is the header2.php file and Im still working on getting the page template up, pastebin doesnt seem to want to accept it

    header2.php
    http://pastebin.com/CYZU1eT7

  18. David
    Member
    Posted 3 years ago #

    If only i had followed Alx's recommendations exactly I would have had this complete a week ago. I didn't name the header file exactly the way he instructed so it wasn't working, as soon as I renamed it header-header2.php it worked perfectly. Thank you everyone for all of your help.

  19. Alx Block
    Member
    Posted 3 years ago #

    Great! Glad you got it to work!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.