Custom Page Templates -
The Very Basics
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…
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:
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"]
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.
ResponderEliminarAwesome, 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