Friday, November 7, 2014

Custom Page Template

Your Theme files should include a default page template (named: page.php) or your Theme may also have one or more custom page templates, for instance, to display content in wider columns. But if you need to make a different layout other than that the theme's layout then you can try making Custom Page Templates and make the layout as per your requirement other than that your theme provides.

You can select the page template by going to  Pages > Edit page > On the right side you can see Page Attributes > Under That from the templates drop down you can select the required template.



By selecting template for page, your page will behave the layout and styles as per that template. But what about a custom layout of your choice rather than then theme's inbuilt ones?

Creating Custom Page Template

 

A Custom Page Template can be used by multiple Pages (see Selecting a Page Template above). To create a custom page template make a new file starting with a Template Name inside a PHP comment. Here's the syntax:
<?php
/*
Template Name: My Custom Page
*/

Once you upload the file to your Theme's folder, the template name, "My Custom Page", will list in the Edit Page screen's Template dropdown. (The select list has a maximum width of 250px, so longer names may be cut off.) 

A quick, safe method for making a new Page template is to use with a copy of your page.php: This way you start off with the HTML structure of your other pages, then you can edit as needed.
A custom page template file can be in a sub-folder, or, if using a Child Theme, in its Parent Theme's folder. 

You need to place this in a PHP file called mycustomepage.php (say) inside the theme folder and in the file you can add the custom layout of your requirement and then just select the layout under Pages > Edit page > On the right side you can see Page Attributes so that that page will follow the layout what you have designed in the file.


Now enjoy with your own template irrespective of the theme and its layout.

For more information please refer: Codex