While designing your WordPress site, you may want to create a page that’s different from your other pages and posts. I’ve created many websites which have a custom home page, portfolio section, site map etc… WordPress allows you to create custom templates in a few simple steps:
- Open up your page.php or index.php and add the following code at the very top of your page:
<?php /* Template Name: Name of your Template */ ?>
- Save your your file as new-template-name.php (you may want to use portfolio.php, sitemap.php, etc..)
- Upload your file in your themes directory
- In your WordPress admin, edit the page that you want custom and select the newly created template from your “Template” drop down which is found under “Attributes”
That’s all it takes to create the template, but now you will need to customize it to make it look different from your other pages. You may want to have a different background, dimension, etc…
Examples of Custom Pages
If you take a look at the site map on Out of Chaos‘s website, you will find a list of all of the pages. This page could have be created simply by inserting an unordered list in the editor, but if we do it that way, then we’ll need to update it every time a new page is added or deleted. An easier way to generate the list is to use a custom template.
The site map template was created by using the following code:
<?php /* Template Name: Sitemap Template */ ?> <?php get_header(); ?> <div id="content"> <div id="right"> <h2><?php the_title(); ?></h2> <ul> <?php wp_list_pages('sort_column=menu_order&exclude=25&title_li'); ?> </ul> </div> <?php get_sidebar(); ?> </div> <?php get_footer(); ?>
The code above grabs the title of the sitemap page and then generates a list of all of the pages and excludes itself.
The ability to create custom templates allows you to create pretty much whatever you want with WordPress and makes it an ideal Content Management System.