Advertisement
Online Test Banks
Score higher
See Online Test Banks
eLearning
Learning anything is easy
Browse Online Courses
Mobile Apps
Learning on the go
Explore Mobile Apps
Dummies Store
Shop for books and more
Start Shopping

WordPress Page Templates

Although the page-slug.php feature in WordPress is very helpful, sometimes requiring the theme’s user to use the name you chose for a feature is too difficult or unnecessary. Page templates allow you to create a stand-alone template (just like page.php or single.php) that users can use on any specific page they choose.

As opposed to the page-slug.php feature, a Page template can be used on more than one page. The combined features of user selection and multiple uses make Page templates a much more powerful theme tool than page-slug.php templates.

To make a template a Page template, simply add Template Name: Descriptive Name to a comment section at the top of the template file. For example, this is the beginning of a onecolumn-page.php Page template:

<?php
/**
 * Template Name: One column, no sidebar
 *
 * A custom Page template without sidebar.
 *
 * The "Template Name:" bit above allows this to be selectable
 * from a dropdown menu on the edit page screen.
 *
 * @package WordPress
 * @subpackage Twenty_Thirteen
 * @since Twenty Thirteen 1.0
 */

This code registers the template file with WordPress as a Page template and adds One Column, No Sidebar to the Template drop-down list found under Page Attributes in the Add New Page (or Edit Page) screen. Using a template on a static page is a two-step process: Upload the template and then tell WordPress to assign the template by tweaking the page’s code.

image0.jpg

The preceding code sample demonstrates how the WordPress developers created the One Column, No Sidebar Page template in the Twenty Thirteen theme; however, in reality, you need only three lines to make it happen. Here is the code that appears at the top of the static-page template that was used on the About page at webdevstudios.com/about:

<?php
/*
Template Name: About Page
*/
?>

The important part is defining the Template Name between the starting and ending PHP function calls. This tells WordPress to recognize this as a unique template and then include it in the list of available templates within the Page Attributes on the Add New Page screen (it also appears on the Add New Page page).

By providing a robust set of Page templates, you can offer your theme users easy-to-use options for formatting different pages within their websites.

  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus
Advertisement
Advertisement

Inside Dummies.com

Dummies.com Sweepstakes

Win an iPad Mini. Enter to win now!