WordPress.org

Forums

[resolved] How to swop a theme per page on a site (9 posts)

  1. Petervee
    Member
    Posted 6 years ago #

    I need to change the layout of a single page on a website layout. Can this be done?

  2. Josh Leuze
    Member
    Posted 6 years ago #

    Yes, you need to use a page template to do this. The documentation can tell you exactly how to create a page template.

  3. gilliancs
    Member
    Posted 6 years ago #

    You then need to choose the new template when you create the page you want to show with the new template. Look for "default template" on the page creation page.

  4. mlarson154
    Member
    Posted 5 years ago #

    Maybe I'm blind, but I don't see a spot on a create/edit page screen that allows me to change the template for a specific page. I'm running 2.8.4. What am I missing?

  5. miocene22
    Member
    Posted 5 years ago #

    you just make a new php file called single.php (for a single post) or page.php (for a page) and put in the html and php you want to dictate the layout and content and link to a separate css file is required.

    Then place the file in your theme folder

  6. mlarson154
    Member
    Posted 5 years ago #

    Yeah, I know how to create and link to a theme template, but I want to have a separate template for one specific page - my home page for instance. Is there a way to specify a different template for one specific page?

  7. @mercime
    Volunteer Moderator
    Posted 5 years ago #

    Create the special Page Template and upload to theme folder, Page > Add New in Dashboard and choose new page template in write panel and name the page, Go to Settings > Reading and choose the name of the new Page you created as home page. You're done

  8. Mark / t31os
    Moderator
    Posted 5 years ago #

    A different approach would be to switch the header and footer files around.

    Open up whichever file deals with your page or post. If this is a page, then open up page.php, if posts, then whichever file is handling it in your theme (index/single, or whatever applies).

    Then plonk a conditional around it...

    <?php
    if(is_page('somepagename')) {
    	get_header('test'); // Looks for a file called header-test.php
    }
    else {
    	get_header(); // Looks for regular header - header.php
    }
    ?>

    If posts, then ..

    <?php
    if(is_single('x')) { // Change x for the post name or ID
    	get_header('test'); // Looks for a file called header-test.php
    }
    else {
    	get_header(); // Looks for regular header - header.php
    }
    ?>

    Then you'll also need to do this around your footer call, same procedure, but with the word footer instead..

    All the important markup resides (or should do) in both the header and footer files of the theme, by using multiple header and footer files you'll effectively have (depending on what you code into those alternate files) a different looking theme/template.

    You could be it a bit more fancy if you want, and use a function to load different sets of head/foot/stylesheets depending on where you are, but you've only mentioned the need to switch on one page above, so i havn't gone into more detail.

    Does that help?

  9. mlarson154
    Member
    Posted 5 years ago #

    Thank you miocene22, mercime, and t31os_ for all your help. What I hadn't done is create the custom template page and upload it to the theme folder yet. Because I had no custom theme pages, as specified in the link on mercime's post, the option for changing the template did not show up.

    Once I added the template, the option to change the template for the page appeared in the Attributes panel.

    t31os_, your example was a good possibility, too. Thank you for putting together a detailed post to help me.

Topic Closed

This topic has been closed to new replies.

About this Topic