WordPress tips and tricks – Custom Page Templates

Some time ago I posted the first of my tips and tricks for WordPress, and I thought it was about time I posted some more so, to start things off, here is a short tutorial on custom page templates in WordPress.

Custom page templates are very much an underused part of the WordPress software yet they can do some very powerful things. Basically you can create a new template file and then use that to display WordPress pages in a totally different way to normal, adding whatever extra features you want. An example of a custom page on Binary Moon would be the Archives page (I need to rejig my archives, they are getting rather long).

Creating a custom WordPress page template is very easy indeed – all you need to do is create a new template file (I tend to copy an existing page template) in your theme directory and add a small PHP comment to the top of the page. Once this is done the template will show up in the “page template” section of the write/ edit page screen.

The code should look like…

<?php /* Template Name: Name of template here<br></br>*/ ?>

Make sure you replace “Name of template here”, with the whatever you wish to call your template.

To use the template simply go to the write page screen, find the “Page Template” panel, and select the template you want to use. Hit save and the page will be formatted using the new template.

Once this is done you can change the template file to do anything you like. Below is a very simple example of an archives page template.

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

<?php get_header(); ?>

	<h1>Archives</h1>

	<h2>Archives by Subject</h2>
	<ul>
		<?php wp_list_cats(); ?>
	</ul>

	<h2>Archives by Month</h2>
	<?php wp_get_archives(); ?>

<?php get_footer(); ?>

Archives aren’t the only thing the custom page templates are good for – you can use them for many different things – for example you could make a custom contact page with a contact form, or a new style of links page using the built in blogroll features. In Elemental I have added over a dozen different custom page templates. There are many possibilities!

How was it for you? Let me know on BlueSky or Mastodon

(Please) Link to this page

Thanks for reading. I'd really appreciate it if you'd link to this page if you mention it in your newsletter or on your blog.

Related Posts

16 Sep 2009

What’s new with the Elemental WordPress theme?

Elemental is the upcoming theme framework for Pro Theme Design. It’s been in development for absolutely ages, and the code is really showing it’s maturity, and I am really pleased with the possibilities it opens up.The focus when developing Elemental...
31 May 2007

WordPress tips and tricks – functions.php

Functions.php is a little known wordpress template file. Not many themes take advantage of it but , used properly, it can be incredibly powerful. The file can be used as a way to add your own functions to wordpress themes...
25 Jul 2007

WordPress Tips and Tricks – Custom Login Page

It’s cool to have the WordPress login page customized to fit your own website branding. This is even more significant for multi author blogs, or sites you have set up for clients as it adds that little extra something.Since writing...
22 Apr 2010

How to Build the Perfect WordPress Sitemap

I was recently asked how I built the sitemap on Binary Moon so I thought I would share the code. The sitemap layout is actually one of the many custom page templates available in my WordPress theme, Elemental – however...
01 Apr 2015

The State of WordPress Themes #wcldn

I recently spoke on a panel at WordCamp London 2015e. Lance – who used to be the Theme Team lead at WordPress.com – asked me if I wanted to speak on a panel with him at WordCamp London 2015. I’ve...