Wordpress Custom Page Templates
Sometimes you may want to create a page on your Wordpress website that looks and acts different than the default page that comes with your theme. For example, your default page may have a sidebar, but you need to add a page that does not have a sidebar. This can be done by creating a custom page template in Wordpress.
What are page templates?
Page templates are just like any other template in your Wordpress theme – they display your content. You can customize the style/layout any way that you would like and you only use them when you specifically choose to use them.
When you create a new page in the Wordpress editor they are created using a page.php file. The page.php file is called the Default Page Template. It usually just loads your content and displays it like a single post.
If you are familiar with the Twenty Ten default Wordpress theme, you can see that there is already a page template called: “One column, no sidebar”.
How to create a custom page template
Let’s say, for example, that you have a sidebar on all of your pages in your website, but you want to have a page that doesn’t have a sidebar. Here is how you make a custom page template without a sidebar:
1) Create a new file in your theme folder and name it noSidebar.php.
2) Open page.php and copy all of the code and paste it into the newly created noSidebar.php.
3) Make any changes that you would like to noSidebar.php. In this example we are going to remove the sidebar, so find the code that calls the sidebar (<?php include('sidebar.php'); ?>) and remove it.
4) You may also want to find the div that contains the main container and add a width style to make it cover the whole page.
5) Finally, and most importantly, add the following line of code to the top of the page. This code is used to tell Wordpress that this is a custom template. Without this code, Wordpress would not be able to find the template: <?php /* Template Name: Your Page Name */ ?>
6) Save this file and upload it to your server.
How to select a page template
Once you make the custom page template, you need to select the page that you want to use it on in the Wordpress editor. To do this, create a new page (or open an existing one). On the right side of the screen you should see a “Page Attributes” box. In this box find the "Template" dropdown and select the name of the template that corresponds to the template name that you just created.