Quantcast
Viewing all articles
Browse latest Browse all 10

Page Templates: Completely Control your WordPress Pages

There is a very powerful, built-in feature to WordPress that lets you add a file to your theme, that can be used to control how an entire page is displayed.

The Idea Behind

 

The idea behind the page templates is that you can create a page from your WordPress admin panel and then override the default page display with anything of your choice, meaning either to completely change the site structure and look (still within your same WordPress site) or to include something dynamically (like PHP) into your page.

The Basic Syntax

 

Creating a file that is to serve as a page template is really simple. All you need to do, is to append a little code snippet at the top that will tell WordPress that it is a page template as well as what name the template has got.

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

By adding this little string at the top of any file that you wish to make into a page template and putting it in your theme folder, WordPress will automatically recognize it. Just swap out My Page Template for something more exact and descriptive for your own template.

Remember, this will be loaded as the theme for the page that you configure this for (more on how to do that in the next section). If you want your header and footer to be showing, you will need to use WordPress template tags to make this show. You can always base your new page template on for example the default page.php but just adding the snippet at the top, then changing what you need.

Setting the Template Up for a Page

Image may be NSFW.
Clik here to view.

You will need to go to your WordPress admin (http://yourdomain.com/wp-admin/), click on the Pages section in the navigation and either edit a page you already have to get the template, or make a new one.

In the right hand side, under Attributes, you will see a dropdown for the Templates that you’ve got. Select your template from the drop-down and click on "Publish"/"Update Page" to activate it.

Again note that unless your page template supports content from the page itself (through the the_content function), any content added in the content area will be disregarded and not be displayed on your theme.

 

This is just the bare-bones and basics of WordPress Page Templates, but with these, you can do some truly advanced implementations, creating pages that act as special listings. By combining this with the post specific tags and creating if/else statements using WordPress functions, you can create very powerful pages.


Viewing all articles
Browse latest Browse all 10

Trending Articles