Using WordPress Page Templates

Filed as Features, Guides on May 24, 2007 10:17 am

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.

Happy Coding!

Nathan Rice is a blogger and freelance web designer. He co-operates RockinThemes.com, and is a contributer at Performancing and WordPressThemes.com

Tags:

This post was written by

You can visit the for a short bio, more posts, and other information about the author.

Submissions & Subscriptions

Submit the post to Reddit, StumbleUpon, Digg or Del.icio.us.

Did you like it? Then subscribe to our RSS feed!



  1. By Tony D. Clark posted on May 24, 2007 at 12:04 pm
    Want an avatar? Get a gravatar! • You can link to this comment

    I love how easy this is to implement in 2.1+.

    I just spent time this morning setting up several different templates for a new site. It makes the use of WP as a true CMS much easier.

    Here are a couple of great articles that give some more info (especially on a static home page):

    http://www.richandstephsipe.com/wordpress/2007/02/12/wordpress-21-static-homepage/

    http://www.richandstephsipe.com/wordpress/2007/04/24/wordpress-loop-in-a-static-homepage/

  2. By Jim posted on May 24, 2007 at 3:38 pm
    Want an avatar? Get a gravatar! • You can link to this comment

    Yep, the easy of implementing it in 2.1 is a huge + in my eyes.

  3. By 鲜花 posted on June 1, 2007 at 11:50 am
    Want an avatar? Get a gravatar! • You can link to this comment

    In accationally I come here and read your articles. It’s very nice. I can not express my feeling in english very well so like this.

  4.   Things you should know when displaying pages in Wordpress — BlogoSquareJune 30, 2007 at 2:39 am
  5. 我爱水煮鱼 » 使用 WordPress 页面模板July 6, 2007 at 1:41 am
  6. 使用 WordPress 页面模板 - DreamRainyMay 1, 2008 at 8:57 am
  7. WordPress Single Post Templates | Nathan RiceMay 13, 2008 at 1:48 pm
  8. Creating a “Blog Page” — With Paging | Nathan RiceMay 14, 2008 at 12:32 pm
  9. Wp Wordpress » Blog Archive » Creating a “Blog Page” — With PagingMay 14, 2008 at 1:33 pm
  10. Wp Wordpress » Blog Archive » Creating a “Blog Page” — With PagingMay 14, 2008 at 1:33 pm
  11. 使用 WordPress 页面模板 at 第七封印May 20, 2008 at 12:05 pm
  12. Confluence: Team: Interactive Media & DesignJune 18, 2008 at 7:37 am
  13. 使用 WordPress 页面模板 | 神無June 27, 2008 at 7:52 am
  14. RedAikido.com» Probando »singleDecember 20, 2008 at 10:39 am
  15. Create an Auto-Stats Page for AdvertisersDecember 29, 2008 at 11:04 am