This will probably be the shortest tutorial in this series, but it is none the less important. On this 11th Day of WordPress I’ll show you how to make a basic custom page template and give you some ideas of how to use them to make your site more interesting.
What is a Custom Page Template?
A custom page template is an alternate template you can use to format your pages. You can add as many custom page templates as you like and you can use them interchangeably. The custom page temlate gives you the ability to create custom layouts for different static pages on your site so they look and behave differently than other portions of your site, most notably the posts.
Custom page templates have many uses. The most common one is probably to create a custom front page that looks different. I use custom page templates to format front pages of sites all the time because they allow me to insert active content that doesn’t fit on other pages. You can see an example of this on the Everybody Dance website.
I also use custom page templates to differentiate between different kinds of page content. For the Frugalbits site I built a series of different page templates. There’s one that looks like the rest of the site used for things like the What is Frugalbits page, there’s one that has just one sidebar with different content for the Legal pages, and yesterday I built a new custom page template with some fancy loop functions to handle the new Frugalbits Cheap Sheet page. Bottom line is the custom page template gives me the ability to customize content in an easy way without having to jump through hoops. And that makes my life easier.
The Custom Page Template in 5 lines of code
Now for the tutorial part: To create a custom page template, find the page.php file in your current theme or parent theme, make a copy, call it something else (like frontPage.php) and open it in your HTML editor.
At the top of the page paste in the following five lines of code:
<?php /* Template Name: Whatever */ ?>
Change “Whatever” to a short descriptive name for your new page template. It can be a name with spaces like “Front page without sidebar”.
Make whatever changes you wanted to make like calling a different sidebar, taking the sidebar out, changing the divs or adding new content, save and upload the file to your theme or child theme folder and WordPress will find it automatically.
Using custom page templates
Now that you have a custom page template it’s time to use it. You can do this from the Edit Page page or using Quick Edit in the page list inside WordPress. You’ll find the Template drop-down menu under Page attributes. From here you simply select the template you want and click Publish or Update and it is automatically applied to your page. And here’s the best part: If you change the page template and find you don’t like it, you can just go and change it back to the default or another template. Nothing is ever final in WordPress.
This should give you an indication of why I like custom page templates so much. Now go out and make your own!
This tutorial is part of the 24 Days of WordPress series. If you want to learn more about WordPress and Expression Web check out the Sams Teach Yourself Microsoft Expression Web in 24 Hours series (version 2, 3 and 4), Lynda.com’s WordPress 3.0 Essential Training course and Microsoft Expression Web 4 LiveLessons.