Imagine that you have some pages containing a lot of content which you want to display across the full width of the page, without the sidebar getting in the way. The way to handle this is to create a page template which doesn't include the sidebar, and then select that page template when you're creating or editing those pages. Let's try it out.
page.php
file and call it page-no-sidebar.php
.<?php get_header(); ?>
, insert the following code:<?php /* Template Name: Full width page without sidebar */ ?>
<div class="content left two-thirds">
<div class="content left full">
<?php get_sidebar(); ?>
and delete it.We created a new template file called page-no-sidebar.php
, and edited it to display content differently from our default page template:
.content
div, using the object-oriented approach to styling used by the layout-core.css
file. This will apply styling for the .full
class to this div, so that it displays a full width instead of two-thirds of its containing element.get_sidebar
include, so that it won't be displayed on any pages using this template.The lines we added at the top are essential for WordPress to pick up on our page template and make it available in the WordPress admin. Page editors will see a drop-down list of page templates available, and the name we defined in the template is what they'll see in that list, as shown in the following screenshot:
As you can see, in the Page Attributes box to the right-hand side, a new select box has appeared called Template. Our new page template is listed in that select box, along with Default Template, which is page.php
.
Now we can try it out by assigning this template to a page and seeing how it looks.