Welcome to the latest tutorial which today is about page templates. This tutorial applies for both WordPress, WordPress Mu and BuddyPress – applying a page template to a page works the same. It’s a nice short one so lets get straight into it with the video and after will be the full tutorial post.
Create the page template
For demo purposes we’re going to use the structure of page.php from the BuddyPress 1.2 Default theme and this theme for the demo itself.
At the top of the theme declare the template name by adding php comments and then by adding the name like this:
Template Name: About
Either add the custom code, formatting or whatever you want for the template in the rest of the code. For this demo we’re going to add the line “This is now using the about template”.
Save the page.
It’s often a good idea to save your pages using a naming convention we’re going to call this page templateabout.php but other good ones are by prefixing template_ or template-. By adding a prefix it makes it easy to identify which are your custom template files in a theme.
Assign the page template to the page
First you need to pick the page in this case the about page.
Then we want to go to the far right and find the section that says Attributes and then Templates under that there is a drop down and lets find the about one.
Remember to update your page to save it or if it’s a new page you’d be publishing it.
View the page template
Now go to the front and on the about page you will now see your template being used. There you go, that’s how you use page templates and it’s a world of possibilities. Many themes have built in templates common ones are full width, blog/news, sidebars to the left or right and 3 column layouts – however many have special templates also. You can read more about page at the WordPress Codex.
Going deeper into page templates next week
Next week we will build on this tutorial by showing you how to assign a blog or news template and a static home page along with more information on home page templates when we dive into the settings and templates.
We hope you are enjoying our tutorial series here at BuddyDress. If there are any tutorials you’d like to see just contact us.