Creating Page Temaplate In WordPress


Page Templates

Pages are one of WordPress’s built-in Post Types. You’ll probably want most of your website Pages to look about the same. Sometimes, though, you may need a specific Page, or a group of Pages, to display or behave differently. This is easily accomplished with Page Templates.

Selecting a Page Template

Screenshot of Page Attributes module with Template select options pulled down

Your Theme files should include a default page template (named: page.php). Your Theme may also have one or more custom page templates, for instance, to display content in wider columns. Or you may have created a custom template of your own.

Edit Page Screen: You can assign a custom template for any individual Page by using the Template dropdown in the Edit Page screen (part of the Page Attributes module):

  1. Select a Template from the list (e.g., My Custom Page).
  2. Click the Update button (or Save Draft if not yet published).

All Pages Screen: The Quick-Edit and Bulk Edit options on theAll Pages screen also have Template dropdowns.

Template List Will Show Only If:

  • There is at least one custom page template file in your active Theme’s folder. If you change your Theme, the page templates in your previously activated Theme will not display.
  • You are viewing a screen for editing a Page: page templates are not a default option for posts or custom post types.

Creating a Page Template

WordPress offers several ways to display Pages. All involve editing or adding files in your active Theme’s folder. If your active theme is not one that you have designed yourself, use a child theme to make the changes. Otherwise the changes will be overwritten when the theme is updated to a new version.

Conditional Tags

Edit your default template: You can often make smaller Page-specific changes with Conditional Tags in your Theme’s page.php file. For instance, this code loads one header file (header-home.php) for your front page, another for your About page (header-about.php), and the default header.php for all other Pages:

if ( is_front_page() ) {
    get_header( 'home' );
} elseif ( is_page( 'About' ) ) {
    get_header( 'about' );
} else {
    get_header();
}

Custom Page Template

Create a template that can be used by any Page: A Custom Page Template can be used by multiple Pages (see Selecting a Page Template above). To create a custom page template make a new file starting with a Template Name inside a PHP comment. Here’s the syntax:

<?php
/*
Template Name: My Custom Page
*/
?>

Once you upload the file to your Theme’s folder, the template name, “My Custom Page”, will list in the Edit Page screen’s Template dropdown. (The select list has a maximum width of 250px, so longer names may be cut off.)

A quick, safe method for making a new Page template is to use with a copy of your page.php: This way you start off with the HTML structure of your other pages, then you can edit as needed.

A custom page template file can be in a sub-folder, or, if using a Child Theme, in its Parent Theme’s folder.

Advertisements

COMMENT PLEASE..!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s