WordPress.org

Ready to get started?Download WordPress

Forums

Can not remove header and footer from homepage (31 posts)

  1. Maracas1970
    Member
    Posted 2 years ago #

    Hello one and all.

    I have created a fairly basic WordPress theme and uploaded it to the Themes directory. So currently i have a folder with style.css index.php, header.php & footer.php no sidebar yet as i only want to use one on my blog page, which hasn't been uploaded yet.

    The landing page is the only page that i don't. want the header and footer to appear on

    The problem i'm finding is that no matter how many times i try to write the conditional statements to remove header and footer.php it is never removed. Some code examples:

    My index.

    http://pastebin.com/f3HnBYyw

    My header

    http://pastebin.com/BTCnpsJ4

    My footer

    http://pastebin.com/QS3Ly2wa

    I have tried putting statements in various places, i think my problem apart from being complete novice is i don`t understand which page i need to reference in the if statement.

    I have tried:
    <?php if( !is_page( '1' ) ) : ?> {with various page numbers}

    <?php if( !is_home( '' ) ) : ?>

    <?php if( !is_front_page( '' ) ) : ?>

    Each time i have wrapped this around the code in the header and footer.

    I hope this makes some sense to someone, and i have tried unsuccessfully to rectify this using existing posts.

    Many thanks

    Kark

  2. Can you please post your code to pastebin.com? It was mucking up the forums.

  3. Maracas1970
    Member
    Posted 2 years ago #

    Apologies, hopefully that`s better.

  4. Peter_L
    Member
    Posted 2 years ago #

    You need both header and footer on each page. They should inlcude things like your opening and closing html and body tags.

    What you should do is put the content inside the header and footer files you don't want to show up inside those if conditionals.

  5. Maracas1970
    Member
    Posted 2 years ago #

    Thank you Peter_L

    I realise that i need the opening and closing page tags, in order to have a fully functional document.

    The thing is i just don't want the header and footer on the homepage. I need to find a way to remove these from that landing page, do i wrap the header and footer.php code in a conditional to say such as, if this is the homepage leave out header and footer?

    I am truly stumped, and have a pulsating brain headache ;>

  6. Peter_L
    Member
    Posted 2 years ago #

    The home page is index.php
    Other pages use the page.php template file.

    So just leave out get_header and get_footer on the index.php.

    Watch it though, this wil cause other problems. You need the wp_head() and wp_footer() and these are usually in the header.php and footer.php.

  7. Maracas1970
    Member
    Posted 2 years ago #

    OK. Removing these got me:

    Parse error: syntax error, unexpected '<' in /var/www/html/wp-content/themes/BPR/index.php on line 13

    Do i need to change anything in header and footer.php before i remove these tags please?

    Thankyou

  8. Maracas1970
    Member
    Posted 2 years ago #

    Did you mean i needed the need the wp_head() and wp_footer() in the index.php or in the header and footer files, as they are on the header and footer files, just not in the index.php now i have removed them.

    Warm regards

    Kark

  9. Peter_L
    Member
    Posted 2 years ago #

    I'm saying you need a header and footer. WordPress needs them.

    Here's a solution:
    Make a new header.php and footer.php

    But call them
    header-home.php and footer-home.php

    Put in these files what you want for the home page. In other words, detle what you don't want from this one http://pastebin.com/BTCnpsJ4, put leave all the rest.

    Inside the index.php, call
    get_header('home');
    this will call the header-home.php
    where as get_header();
    calls the header.php template

    That should solve your problem.

    The parse error from a bove is a syntax error. You pade a mistake in the php language.
    But start above, do the stuff I wrote here. That should work, I use it all the time.

  10. Maracas1970
    Member
    Posted 2 years ago #

    ok so when i do that all the styling goes, and i`m left with get_header('home'); at the top left of the page along with all the unstyled links..

    Do i have to copy over all the index.php code into the header-home.php and footer-home.php files? And leave nothing else.
    And delete reference to get footer and get header on the index.php.
    And just add get_header('home'); at the top of the index.php?

    Im sorry, im really confused. Maybe something is lost in translation here, or maybe i`m just tired..

  11. Maracas1970
    Member
    Posted 2 years ago #

    Progress! Got rid of the header, And got rid of the text.

    Hopefully can repeat for footer afterwards, and be on my way...

  12. Maracas1970
    Member
    Posted 2 years ago #

    Hi there.

    Well i thought it was working, but when i checked the header.php file i noticed i`d taken the code out of there aswell as the header-home.php file, when i added it back to the header the same thing happened, unwanted navigation intended for the rest of my pages appeared.

    I did everything you said, the header-home file is in the theme folder as is the footer-home.php which incidentally seems to work.

    Here is my updated index.php

  13. Maracas1970
    Member
    Posted 2 years ago #

    I guess while im at it, heres a link to the website..

    http://www.gotodesigns.co.uk

    Need to get rid of the blue icons and text at the top.
    It just doesnt seem to be calling the header-home.php for some reason.

  14. Peter_L
    Member
    Posted 2 years ago #

    You're not getting the thing you're doing.
    This isn't a conditional. It's a call for a specific template file. If you call both files, both files will show.
    Read this http://codex.wordpress.org/Function_Reference/get_header

    You call both:

    get_header('home');
    get_header();

    so both will show

    +

    all the code between rule 15-25, you put inside the header-home.php
    on rule 26 you call wp_head() (inside the header-home.php file)
    ...

    header-home.php isn't an empty file you call, it should contain all the header info for the page you call it for. In this case, all header info of your home page.

  15. Maracas1970
    Member
    Posted 2 years ago #

    Do i need all this in my index page:
    <title><?php wp_title('«', true, 'right'); ?> <?php bloginfo('name'); ?></title>
    <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
    <link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
    <?php wp_head(); ?>

    because when i added that before the end head tags, it seemed to work even when i exclude the get_header('home'); its really bizarre..

    When it`s excluded just with the get_header('home'); included, all the styling disappears. Until i put it back in.

  16. Maracas1970
    Member
    Posted 2 years ago #

    Thanks for all the time/help you put in so far by the way.

    As you can see, i am only just beginning with PHP & WordPress.

  17. Peter_L
    Member
    Posted 2 years ago #

    No, that goes inside your header.

    Look a basic page looks like this
    header
    the loop
    sidebar
    footer

    Your home page should look like this
    header-home
    the loop (or some static content if you want)
    sidebar
    footer-home (if you want)

    You could just forget about the entire header-home thing, but it's cleaner, simpler and should spare you from other problems.

    You want a specific header for the home page.
    So, the index.php (home page) gets the specific header header-home.php

  18. Maracas1970
    Member
    Posted 2 years ago #

    I don't have a sidebar for the homepage, was only intending to use this for the blog page, is this OK? Or will it cause problems?

  19. Maracas1970
    Member
    Posted 2 years ago #

    Also when i go to my appearance/editor within WordPress i only see three files. index, footer and header, why dont the other files i created and uploaded to the same directory show here eg: my footer and header home files.

    Also dont have the option in add pages to create new template page..

    Thanks

  20. Peter_L
    Member
    Posted 2 years ago #

    no sidebar is no problem
    the header-home.php should have commenting on the top, same as the header.php but adapted
    That way, Wp recognizes it

  21. Maracas1970
    Member
    Posted 2 years ago #

    i just have the same commenting as the header.php which is

    <?php
    /**
    * @package WordPress
    * @subpackage BPR
    */
    ?>

    Do i need to include something else in here, this is the same comment that is on all my pages.

  22. Peter_L
    Member
    Posted 2 years ago #

    No, hold on, the commenting shouldn't matter.
    Just doublechecked it.

    It should be there. Are you sure you uploaded those files + put them next to other template files?

  23. Maracas1970
    Member
    Posted 2 years ago #

    Oh dear, i thought i was reasonably good at following instructions..

    I have done all the things you said to my knowledge. I will include where i am with header-home and my index.php now. Just incase it`s something obvious.

    the index: http://pastebin.com/Mb0rtJNd

    the header-home: http://pastebin.com/wkKJ3gGn

    Im going for a cup of tea. ;-)

  24. Maracas1970
    Member
    Posted 2 years ago #

    Sure they are in my wp-content/themes/bpr/folder

    This is what i keep imagining, that they are simply not there.

  25. Peter_L
    Member
    Posted 2 years ago #

    Omg, I can't explain worth shit.

    Suppose an html file

    <html>
    <head>some meta</head>
    <body>some text</body>
    </html>

    What wordpress does is
    put the html and head inside the header.php
    most of the body inside the index.php
    the rest inside the footer.php

    So inside your index.php, first thing you do is tell wordpress to get all the things from inside header:
    <?php get_header(); ?>
    next comes the real content, in your case the static content inside id="home-nav"
    after that is done, tell wordpress to get the footer
    <?php get_footer(); ?>

    What you just did was to put everything inside the custom header file (header-home.php) and then everything inside your index file and just blend it all together.

    I you can't grasp that you'll to start WordPress 101.

  26. Maracas1970
    Member
    Posted 2 years ago #

    OK

    so i have taken all the code out of the header-home.php & header.php files that was not needed, and only included the parts i want to include for the separate pages in the site.

    For example i have included the home navigation code in the header.home.php file, and the homepage image.

    And the code i want to use in the rest of the site in the header.php file, ie, the main site navigation and a banner link/image.

    I have taken the meta out of the index.php as if i understand correctly that`s needed in the header and nowhere else.

    so to reiterate. this is my index.php: http://pastebin.com/6MDfMabe

    this is my header( the one i wish to use for the rest of the site but not on the home page: http://pastebin.com/pMmWajUV

    And finally this is my header-home.php file: the one i want to use only for the homepage: http://pastebin.com/p5FspqXV

    Please tell me i`m not going mad. I am still not getting the other files i have created to be seen within the wordpress appearance/editor either. And still cannot create custom template from the pages menu, simply isnt the option there..

  27. Peter_L
    Member
    Posted 2 years ago #

    It's better but still some problems

    So, the home page opens the index.php

    Inside the index.php WP encounters this <?php get_header('home'); ?>, wich means, go to header-home.php grab everything that's in there and paste it 'here'.

    The header-home.php has the opening html, the entire head section, all ok then 2 opening body tags (you can only have one) and has some navigation and then an image you basically use as main content.

    Then the rest of the index.php file gets loaded. 2 opening body tags (which makes 4) again, the nav, again that same main content image. Ends with closing the entire html document off and then calling the wp_footer().

    You see the problem? It's a flow and you're loading a lot of things twice.

    It's ok to have the nav inside the header file. So, let's keep that there.
    So in your index.php, delete everything starting with the first opening body tag (line 10) and ending with the closing div tag of the nav div (line 22). Also leave out <?php wp_footer(); ?> for now. We'll solve that later.

    In your header-home.php delete the home-content div and the following closing div of the wrapper. (lines 35 and 36)

    Not sure why you can't edit these files inside WP.

  28. Maracas1970
    Member
    Posted 2 years ago #

    The problem really does seem to be that it cannot reference the header-home.php file. For some god forsaken reason it just aint doing it..

  29. Peter_L
    Member
    Posted 2 years ago #

    can you mail me the theme folder to peter@lidee.be ?

  30. Maracas1970
    Member
    Posted 2 years ago #

    Sure..

Topic Closed

This topic has been closed to new replies.

About this Topic