In WordPress, a Page is used to display information other than regular posts and it lives outside of the normal blog chronology. In the default Kubrick theme there are 3 Page Templates that can be used to display the content of a Page:
page.php - Default Page Template, displays Page content
archives.php - ignores Page content and instead displays a list of Archives
links.php - ignores Page content and instead displays your links
So which Template does WordPress use to display the content of a particular Page? WP will search your theme's files for templates and use the first one it finds in this order:
The Page's selected Page Template
page.php
index.php
Now you probably don't want to remove the sidebar from page.php because that will remove it from ALL Pages using that Template. So, we simply create a new Page Template and assign it to the Page that you don't want the sidebar to appear in. This is not as difficult as it sounds. Simply create a duplicate of your theme's page.php but leave out the call to the sidebar. In the default Kubrick theme the tag that calls the sidebar is ...
My theme is a little different. I have 2 sidebars and they are called as ...
... but we'll stick to using the first tag. Open up your theme's page.php and copy/paste the contents into a new file. Leave out the tag that calls the sidebar. Using the example provided by the Codex, place this at the very top of your new file ...
... and save it as snarfer.php. Upload the new Template to your theme directory. Now, when you create a new Page you simply assign your new Page Template - in this case snarfer.php - to display its content.
Of course after doing this you may want to make further adjustments since you will now be left with a strange looking empty space where the sidebar used to be. You will probably want to widen the content area so that if fills that empty space. All you need to do is rename the DIV that holds your content in your new Page Template then add its styling attributes to your style sheet. You can see how this is done by studying the differences between index.php and single.php in the default Kubrick theme. Notice how one uses class="narrowcolumn" and the other uses class="widecolumn".
If you want to see a live example of this in action click here. [demo currently unavailable]
Update: After reading this post I thought perhaps that I would include the other option I provided in the forum for the benefit of anyone reading this in the event you don't see that forum post. This option for removing the sidebar from a certain Page involves the use of conditional tags. Look in your theme's page.php for the sidebar call. Once again, using Kubrick as an example, that would be ...
... and add a few lines of code around it so that it now looks like this ...
... where "x" is the ID number of that Page. What this says is "if we are on page "x" do nothing and if not get the sidebar". While this method may be easier I prefer creating a new Page Template. Anyway, you now have 2 methods to hide your sidebar on certain Pages.
Further reading:
http://codex.wordpress.org/Pages
http://codex.wordpress.org/Pages#Page_Templates
http://codex.wordpress.org/Conditional_Tags
page.php - Default Page Template, displays Page content
archives.php - ignores Page content and instead displays a list of Archives
links.php - ignores Page content and instead displays your links
So which Template does WordPress use to display the content of a particular Page? WP will search your theme's files for templates and use the first one it finds in this order:
The Page's selected Page Template
page.php
index.php
Now you probably don't want to remove the sidebar from page.php because that will remove it from ALL Pages using that Template. So, we simply create a new Page Template and assign it to the Page that you don't want the sidebar to appear in. This is not as difficult as it sounds. Simply create a duplicate of your theme's page.php but leave out the call to the sidebar. In the default Kubrick theme the tag that calls the sidebar is ...
My theme is a little different. I have 2 sidebars and they are called as ...
... but we'll stick to using the first tag. Open up your theme's page.php and copy/paste the contents into a new file. Leave out the tag that calls the sidebar. Using the example provided by the Codex, place this at the very top of your new file ...
... and save it as snarfer.php. Upload the new Template to your theme directory. Now, when you create a new Page you simply assign your new Page Template - in this case snarfer.php - to display its content.
Of course after doing this you may want to make further adjustments since you will now be left with a strange looking empty space where the sidebar used to be. You will probably want to widen the content area so that if fills that empty space. All you need to do is rename the DIV that holds your content in your new Page Template then add its styling attributes to your style sheet. You can see how this is done by studying the differences between index.php and single.php in the default Kubrick theme. Notice how one uses class="narrowcolumn" and the other uses class="widecolumn".
If you want to see a live example of this in action click here. [demo currently unavailable]
Update: After reading this post I thought perhaps that I would include the other option I provided in the forum for the benefit of anyone reading this in the event you don't see that forum post. This option for removing the sidebar from a certain Page involves the use of conditional tags. Look in your theme's page.php for the sidebar call. Once again, using Kubrick as an example, that would be ...
... and add a few lines of code around it so that it now looks like this ...
... where "x" is the ID number of that Page. What this says is "if we are on page "x" do nothing and if not get the sidebar". While this method may be easier I prefer creating a new Page Template. Anyway, you now have 2 methods to hide your sidebar on certain Pages.
Further reading:
http://codex.wordpress.org/Pages
http://codex.wordpress.org/Pages#Page_Templates
http://codex.wordpress.org/Conditional_Tags
Comments
Post a Comment