It's very simple to make a page in our site use our new page template.
We edited one of our pages so it uses the page template we just set up. This is how it now looks in the browser:
The page is displayed without a sidebar, and the content stretches to the full width of the page. Good job!
You may remember that in Chapter 3, Coding it Up, we added the body_class()
template tag to the <body>
tag in our theme's header.php
file, using the following code:
<body <?php body_class($class); ?>>
This tag automatically assigns classes to the <body>
tag depending on what type of content is being displayed and the template file being used. The great news is that you can use it to target our new page template.
Try doing this with your theme, using the .page-template-page-no-sidebar-php
class, which will be assigned to the <body>
tag for any pages using this template.
For example, you could try:
.page-template-page-no-sidebar-php h2.page-title
selectordisplay:none
declaration (although it's much better to delete the content from the template file as then the content won't be output in the first place)There are plenty of possibilities!
For more on creating custom page templates, see http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates.