viernes, 19 de junio de 2015

Custom Page Templates - The Very Basics

Custom Page Templates -
The Very Basics


This tutorial will show you the very basics of how to create custom page templates. Page templates are a great way to create custom layouts for individual pages on your website. There are, of course, other methods to customizing content such as using post formats, custom post types and many other ways. I personally think that custom page templates are the very easiest when learning how to use WordPress as a CMS.

When would you use a custom page template?

There are countless uses for custom page templates although some of the more common uses that I have seen are for the following pages:
  • Full Width Page
  • Left Sidebar Page
  • Right Sidebar Page
  • Archives Page (archives.php)
  • Portfolio Page
  • Contact Page
  • Meet the Team Page
  • Shopping Cart Page
  • etc…
The list could go on and on. Hopefully this gives you some ideas as to the application of custom page templates. We have some tutorials coming up that will utilize custom page templates in much more depth.
To get started, this is how it works. Let’s say you want to create a custom page template for the contact page of your site. Create a file called template-contact.php (The file doesn’t have to be labeled with template-. I prefer to use the template- structure for all custom page templates so they are easier to recognize within the file structure.) and at the very beginning of the file insert the following code:
<?php
/*
Template Name: Contact Page
*/
?>

<h2>Page title...</h2>
<p>The site content... etc</p>
<p>...</p>
Once you have input the given code you can go ahead and create your page however you would like. As far as the basics are concerned, that is all you have to do. Go ahead and save the file and go into the backend to your pages tab. On the right side you will see a new page template with the title that you defined.
Here is an example of what the page templates will look like:
Custom Page Templates
If you have any questions how to use custom page templates in other methods please comment and let me know so I can add to this.
[author id="bradynord"]

2 comentarios:

  1. Hey there Brady, looks good, although you might want to get in a little more detailed of when page templates are applicable, like archive pages, portfolio and other templates. And you might also want to show a couple of screenshots of how those pages are then selected from the admin UI.

    ResponderEliminar
    Respuestas
    1. Awesome, I’ll get that in there today. My thoughts with this were that I would show a complete beginner of WordPress how to use this basic feature. To be honest, this is one of my favorites. ha

      Eliminar