Creating your own page template is straightforward, as the simple example in this section shows. The process gets more complicated when you want the template to do something more useful. Chapter 12, which deals with themes, covers a few of the WordPress tags you can use to turn this template from a proof of concept to something that may be useful for your blog.
Page templates are located in the root of your theme's folder. For this example, you add a template to the default WordPress theme.
To create an example page template, follow these steps:
1. Open your text editor of choice.
I like TextMate in Mac OS X, but you can use any free text editor that's available for your platform, such as Notepad or TextEdit.
2. Type the following code:
Template Name: Example Template */
This code tells WordPress that the file is a page template. The Template Name parameter sets the name of the template, which will be displayed in the Page Template drop-down menu (refer to "Page Template" earlier in this chapter). In this example, you name the template Example Template because I have no imagination.
The rest of the template is code that does something.
3. Enter the rest of the example template, which calls the header and footer of the current theme and displays a message:
4. Save the template as a PHP file.
Make sure that the file extension is .php; otherwise, the file won't work.
5. Upload the template to the default theme folder, which is located here in your WordPress installation:
wordpress is the directory containing your WordPress installation.
The template should appear in the Page Template drop-down menu now (Figure 8.7). Pretty cool, huh?
Figure 8.7 The example template displayed with the rest of the page templates.
Default Template j -
If you visited a page that actually used this template, though, the template wouldn't serve any useful purpose; it wouldn't even display the Hello, world! message in an attractive way. See Chapter 12 for details on transforming this template into a helpful page.
Was this article helpful?
Are You Ready to Start Writing? Times are very hard, and there is no reason to assume or imagine that things are going to improve any time soon. The world as a whole has undergone some very traumatic changes over the last few years, and the financial situation in most countries seems grim.