Every WordPress theme comes with a page template (page.php). This file is the default template for WordPress pages.
Unfortunately, many themes do not come with a 404.php file for 404 pages, an archives.php file for an archives page or an author.php file for an author archive. Thankfully, it is very easy to create these files and the main code used within them can be taken from your themes page.php template.
I am not sure what designers call this code but I like to call this code the ‘Page Shell’. The ‘Page Shell’ is simple the code from the page.php template with the WordPress Loop removed.
The page.php template in every theme is slightly different. Though you shouldn’t find it too difficult to remove the WordPress Loop code from the page.php file. All you have to do is remove everything from to .
Creating the Page Shell
Here is an example page.php template from the WordPress Default theme:
<?php /** * @package WordPress * @subpackage Default_Theme */ get_header(); ?> <div id="content" class="narrowcolumn" role="main"> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <div class="post" id="post-<?php the_ID(); ?>"> <h2><?php the_title(); ?></h2> <div class="entry"> <?php the_content('<p class="serif">Read the rest of this page »</p>'); ?> <?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?> </div> </div> <?php endwhile; endif; ?> <?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?> <?php comments_template(); ?> </div> <?php get_sidebar(); ?> <?php get_footer(); ?>
I just need to remove the WordPress Loop from the code above in order to get the Page Shell. I also think it’s wise to remove the package comments from the start of the template and the edit and comments link too since I will not be needing them in the pages I am using the page shell for. Additionally, I have removed the role attribute.
So here is what my final Page Shell looks like:
<?php get_header(); ?> <div id="content" class="narrowcolumn"> Content and functions will be placed here! </div> <?php get_sidebar(); ?> <?php get_footer(); ?>
Using the Page Shell
It may not be apparent just now, but once you have this shell code you can easily create other WordPress templates incredibly easy. Over the next few weeks I will be showing you how you can use your Page Shell to create other useful templates.
As always, if you are unsure about any of this, please let me know.