Using WordPress Page Templates

If you have ever developed a WordPress Theme for someone, you may have run into this request:“Could you make each page have a different [insert design aspect here]?”

Well, if you’re just using the page.php file to handle the look of all your pages, the answer may be “no”. But if you use different page templates, you certainly CAN make any page look however you want.

For instance, let’s say you have a client that wants all the pages to have the sidebar except for his bio page. On his bio page, he wants the content to extend all the way over where the sidebar used to be. Here’s what you do:

Create a new template in your theme folder called bio.php (or whatever you want to call it)

Then copy the contents of your page.php template into the bio.php file.

After that, find the place where the template calls the sidebar and remove it or comment it out (I’m assuming that if you’re a theme designer, you know what I’m talking about. If not, there are plenty of WP theme tutorials out there).

You’ll probably also want to find your content div and manually add a width style to it to extend the width to fill the entire container.

After you’ve done all that, go to the very top of the bio.php page and insert the following code above the call for the header:

<?php
/*
Template Name: Bio
*/
?>

Once you get this code at the top of the template, save your file and upload it to your server.

Now, it’s time to use the WordPress admin to get the bio page to use the Bio template. Here’s how, in case you don’t know.

Either write a new page, or edit the bio page (if you’ve already created it), and on the right side, you’ll see different headers like Discussion, Page Status, Page Password, Page Parent, Page Template, Page Slug, Page Author, Page Order. Click the plus sign next to Page Template and find Bio in the drop-down list. Choose it and click save.

Now you have your bio page using a different template than the rest of your pages.

Obviously, there are a ton of uses for this little trick. I use it in one way or another on just about every client I have (especially the ones who want to use WordPress as an non-blog CMS). If you use your imagination, you can probably come up with some creative uses for it as well.