I was just trying out the new Blogger Pages feature and one of the first things I wanted to do was hide one or both sidebars. In my previous post, I showed how to use conditional code blocks in the template to add unique meta tags to Blogger Pages, which lack labels and categories.
It occurred to me that a simple conditional code block could hide one or both sidebars for a particular Blogger Page, too. It works! I did have to adjust my template to make the center column liquid instead of a fixed width. Doing so allows content to flow outward into space previously occupied by the sidebar. Otherwise, the page would have a blank sidebar with an unchanged center column. I've described changes I made to my Minima template below, in case you want to try it on your blog.
Take a moment to back up your template before making changes to it!
Remember that the changes I describe apply to a 2-column or 3-column Minima template. If you are using a different template, this method may not work without adjustments, or at all. The new "Blogger in Draft" templates use positioning instead of floats for the layout. If you are using a "Blogger in Draft" template, please see these instructions.
Hide the sidebar
Enclose the #sidebar-wrapper div in a blogger conditional tag and make the condition NOT equal to the Page URL. We don't want to hide the sidebar on any page except our "special" one. The pattern is:
<b:if cond='data:blog.url !=
"http://blogname.blogspot.com/p/page-title.html"'>
<div id='sidebar-wrapper'>
<b:section class='sidebar' id='sidebar' preferred='yes'>
<b:widget id='BlogArchive1' locked='false' title='Blog Archive'
type='BlogArchive'/>
[...other sidebar widgets...]
</b:section>
</div>
</b:if>
Remember to replace "page-title.html" in the code with your Page's actual title. Note that blogger changes double quotation marks around the page URL to the entity " when you save the template. The code still works, so don't worry about it.
When you test the new blogger conditional with your Page, the sidebar should be missing. The main column's content will not flow into the empty space until we make a few simple changes to the template layout.
Edit the Minima template
I moved the #main-wrapper div below both of my sidebars, which float left and right:
<div id='newsidebar-wrapper'>
<b:section class='sidebar' id='newsidebar' preferred='yes'>
[sidebar content]
</b:section>
</div>
<b:if cond='data:blog.url !=
"http://blogname.blogspot.com/p/page-title.html"'>
<div id='sidebar-wrapper'>
<b:section class='sidebar' id='sidebar' preferred='yes'>
[sidebar content]
</b:section>
</div></b:if>
<div id='main-wrapper'>
<b:section class='main' id='main' showaddelement='yes'>
<b:widget id='Blog1' locked='true' title='Blog Posts' type='Blog'/>
</b:section>
</div>
Next I removed the float and width from the #main-wrapper div, so that it would flow between them, and changed margins to padding, which works better with floats.
That is, I replaced this:
#main-wrapper {
width: 505px;
margin-left: 30px;
margin-right: 30px;
float: $startSide;
word-wrap: break-word; /* fix for long text breaking sidebar float in IE */
overflow: hidden; /* fix for long non-text content breaking IE sidebar float */
}
With this [I actually commented out the original lines, but for clarity, they are omitted here]:
#main-wrapper {
padding-left: 30px;
padding-right: 30px;
word-wrap: break-word; /* fix for long text breaking sidebar float in IE */
overflow: hidden; /* fix for long non-text content breaking IE sidebar float */
}
Since first publishing this post, I changed my template from Minima to Picture Window, a much more complex template that uses positioning instead of floats for the layout. The simple CSS used to modify the Minima template does not work with Picture Window. In this template, I was able to hide the sidebar by conditionally appending CSS styles that modify the template section widths and hide the right outer sidebar. View the result on the Real Tea page, where I added an Amazon aStore, because making one fit in Blogger is a question that is raised daily. This aStore fits with only one sidebar hidden because I used (one of my own) narrower aStore "shared templates".
I highly recommend editing the aStore <iframe> tag to modify width="100%" to the actual width of the aStore + 17px (for the vertical scrollbar). My aStore <iframe> has a specified width of 697px (680px + 17px). Doing this prevents the aStore from sliding under the sidebar.
If you want to use a narrower template in order to preserve one of your sidebars on the aStore page, here's how. First, edit your aStore on Amazon and in Step 2 - Color & Design, jot down your color theme name and/or your custom colors or Print Screen and view in Paint. Then click Shared Templates and select one of the templates with "Narrow" or "Skinny" in the title. Some time ago, I added three templates to the Shared Template list: Narrow Red Centered, Narrow Earth, and Narrow Blue Centered, which are all 680px wide, not including a 17px vertical scrollbar that will appear on long pages. After you apply a shared template, change the colors back to your original color theme. Doing so will not affect CSS styles in the shared template that make it narrower.
7 comments:
This is helpful, but I'm kind of scared to try doing it without someone to "talk me through it."
(I'll probably try it when I'm less scared of html...which might be a while.)
Question: If you change the static page, wouldn't you also be changing the main blogger page? (Which I don't want to do, as I've just barely got everything arranged to my satisfaction.)
The changes I made to the template layout do affect all pages, so you could try them first after backing up the template. The blog should look the same after the template is changed. If not, it's easy to restore the saved template.
If all is well, then you could add the blogger conditional around one or both sidebars. When the sidebar is not written to a particular static page (because of the blogger conditional), other pages are unaffected.
I'm trying to do it now, but when I follow the directions, I end up losing all of my posts on my blog pages.
Whee! I had to do some extra fiddling around with margins/side bar but I finally got the coding to work. Thanks!
Great! Variations in margins and padding are a hazard, but I'm glad you figured it out for your site.
I was helping someone else today with a 2-column layout, and it worked best when the floated sidebar has the separator margin instead of the center column.
Hi Araby, nice blog! You seem to master the lamp.
I am in the process of building a video blog to be launched in a couple of weeks (and I am far behind schedule). I am using Blogger in Draft, the Awesome Inc. template.
I would like to get rid of the sidebar and expand the main column in two of the pages (or even in all of them) in order to accommodate a larger video player.
Would you please give the lamp a good rub and tell me what the genie suggests it is necessary to do for me to achieve my goal?
Many thanks!
Thanks for the kind words.
This post is too long to add more stuff, so I added instructions in a new one: Hide Sidebar in New Blogger Templates.
If you decide to hide the sidebar on all pages, it would be simpler to select the single column layout in the Template Designer than to mess with the template.
Good luck with your video blog!
Post a Comment