Time for action – assigning a custom page template to a page in our site

It's very simple to make a page in our site use our new page template.

  1. In the WordPress admin, open the editing screen for one of your pages. Here we'll use the About Us page.
  2. In the Page Attributes box, select the template called Full width page without sidebar.
  3. Click on the Update button to save changes to the page.
  4. Now visit the page to see how it looks.

What just happened?

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:

What just happened?

The page is displayed without a sidebar, and the content stretches to the full width of the page. Good job!

Have a go hero – styling the custom page template

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:

  • Changing the color or size of the page title, using the .page-template-page-no-sidebar-php h2.page-title selector
  • Hiding some content on this page only, using the display: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)
  • Moving the sidebar to the left-hand side instead of removing it altogether— using layout styling for the sidebar and the content
  • Adding an additional background image (or a different one) to those pages

There are plenty of possibilities!

Note

For more on creating custom page templates, see http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.140.186.201