Aweber - Email Marketing Made Easy
Show One Sidebar on Certain Pages in Thesis

Show One Sidebar on Certain Pages in Thesis

July 23, 2011 · 0 comments

in Sidebar, Thesis, Thesis User's Guide

This post is part of a series of tips & tricks that I have hand selected from the Thesis User's Guide, and which I have found most helpful when customizing and enhancing Thesis. You should check out the guide for some excellent tips.
Thesis 1.x Notice: Thanks for reading this post! So, here's the deal. I wanted you to be aware that this post was written prior to the release of Thesis 2. So that means the instructions or other information provided applies specifically to Thesis 1.x and not the latest 2.x version. Thanks!

Sometimes you might want to show a single sidebar on certain pages in your Thesis theme if you’re running a 3-column layout. That means you basically have 2 sidebars sitewide, but maybe you just want to show one on a particular page. This tutorial from the Thesis User’s Guide will allow you to do just that.

There are four basic steps to making this happen:

  1. Remove the original sidebars from the home page
  2. Restore sidebar 1 to the home page
  3. Add a unique body class to the home page (to be used for styling)
  4. Add (and modify) the custom styles

The discussion which follows is specific to the home page (aka the posts page) — if you’re wanting to apply this tutorial to another page instead, you’ll want to substitute the appropriate WordPress conditional tag.

To remove the original sidebars from the home page, we’ll use a Thesis filter, thesis_show_sidebars. Add the following code to your custom_functions.php file:

// Remove original sidebars
function no_sidebars() {
	if (is_home())
		return false;
	else
		return true;
}
add_filter('thesis_show_sidebars', 'no_sidebars');

Now that the default sidebars have been removed from the home page, we’ll need a function which adds back only the one sidebar that we want; here’s the code you’ll need in your custom_functions.php file:

// Restore sidebar 1 to layout
function restore_sidebar(){
	if (is_home()) { ?>
	<div id="sidebars">
	<div id="sidebar_1" class="sidebar">
		<ul class="sidebar_list">
			<?php thesis_default_widget(1); ?>
		</ul>
	</div>
	</div>
	<?php }
}
add_action('thesis_hook_content_box_bottom','restore_sidebar',1);

Finally, since Thesis has been configured to display two sidebars by default, but our home page will only be displaying one sidebar, we’re going to need a unique CSS class which we can use to modify the existing styles to accommodate just the one sidebar. For that, we’ll use the Thesis filter thesis_body_classes. Place the following code in your custom_functions.php file:

// Add a class for styling
function one_sidebar($classes) {
	if (is_home()) {
    	$classes[] = 'one_sidebar';
 	}
    return $classes;
}
add_filter('thesis_body_classes', 'one_sidebar');

That’s it for the custom_functions.php file — remember to save all your changes!

Now, add the following code to your custom.css file (you’ll need to change the values until you’re satisfied with the final look for your home page):

.custom .no_sidebars #content { width: 51.4em; }
.custom.one_sidebar #container { width: 100em; }
.custom.one_sidebar #sidebars { width: 21.7em; }

That’s it! Now you’ll see only sidebar 1 showing up on your home page, whereas both sidebar 1 and sidebar 2 will show up everywhere else on your site!

But, what if sidebar 2 is the only sidebar you want on your home page? Simply replace 1 in the second function above with 2 instead, and you’re all set!

Source: Show One Sidebar Only on Certain Pages

Was this post helpful? Consider subscribing to my blog via RSS or

This Site Runs on the Thesis WordPress Theme

Thesis Theme thumbnail

If you're someone who doesn't understand a lot of PHP, HTML, or CSS, Thesis will give you a ton of functionality without having to alter any code. For the advanced user, Thesis has incredible customization possibilities via extensive hooks and filters. And with so many design options, you can use the template over and over and never have it look like the same site.

If you're more familiar with how websites work, you can use the fantastic Thesis User's Guide and world-class support forums to make more professional customizations than you ever thought possible. The theme is not only highly customizable, but it allows me to build sites with a much more targeted focus on monetization than ever before. You can find out more about Thesis below:

{ 0 comments… add one now }

Leave a Comment

When commenting, you can use basic HTML tags. If you are pasting in any code, please escape it here and then include that code within <pre></pre> tags. Thanks!

CommentLuv badge

Previous post:

Next post: