Friday, November 27, 2015

Creating Page Templates in Wordpress

Sometimes we want a template that can be used globally by any page, or by multiple pages.

To create a global template, write an opening PHP comment at the top of the file that states the template’s name.
1
<?php /* Template Name: Example Template */ ?>
It’s a good idea to choose a name that describes what the template does as the name is visible to WordPress users when they are editing the page. For example, we could name your template Homepage, Blog, or Portfolio.
This example from the TwentyFourteen theme creates a page template called Full Width Page:
1
2
3
4
5
6
7
8
<?php
/**
 * Template Name: Full Width Page
 *
 * @package WordPress
 * @subpackage Twenty_Fourteen
 * @since Twenty Fourteen 1.0
 */
basics-page-templates-03Once we upload the file to our theme’s folder (e.g., page-templates), go to the Page > Edit screen in your admin dashboard.
On the right hand side under attributes we will see template.  This is where users are able to access our global page templates.

No comments:

Post a Comment