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!

Was it good/ useful/ a load of old rubbish? Let me know on Mastodon, or BlueSky (or Twitter X if you must).

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

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...
27 May 2013

WordPress: 10 Years Young, What Does The Future Hold?

WordPress is now 10 years old. I started using wordpress 9 years ago – which means I joined the WordPress community early on. The reason I chose WordPress is simply because of the fabled 5 minute install process – I...
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...
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...
28 Aug 2008

WordPress 2.7 and Crazyhorse

Last weekend I spent a few days away from WordPress and work in general to spend some quality time with the girlfriend. When I got back and updated my local copy of WordPress (via svn) I was surprised to see...