Today we are going to look at some more page template types. More specifically we will look at
- page templates
We will start with the Class Files from Tuesday, 4/9/11.
Page templates are basically the same as other template files except that they have a comment at the top that tells WordPress they are page templates. The purpose of these is to allow the a WP page creator to specify a template for a page when they make it in the dashboard.
The templates we’ve worked with so far (index.php, single.php, page.php) are templates that WP automatically chooses depending on what it is showing. So when you view a single page it looks for page.php, when you view a single post it looks for post.php.
So the purpose of page templates is to allow some flexibility with this and let users decide to show a particular template. This only applies to pages, not posts, hence the name Page Templates.
Page Template Comment Snippet
<?php /* Template Name: My Page Template */ ?>
In the example above My Page Template is the name of the template and what users would be able to choose when creating a new page. You can change that to what you like. You must leave Template Name: as it is.
That’s all I’m going to show here because the rest is up to you as a theme designer. Some common examples are a separate template for the page you’re going to use for the font page and one that doesn’t have a side bar. If you look in the files for the twentytwelve theme you will see a folder named page-templates and those two types of page templates inside.
We will make a page template by making turning an existing page into a template.
In WordPress there are ways to look at the archive of posts based on:
There are others like author, but we will deal with the three above today. We will create a file named archive.php that can be used to show the archive pages for the three types above. It contains an if/else statement for the title that writes out the title appropriately and then shows a list of the posts below.