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:
- Remove the original sidebars from the home page
- Restore sidebar 1 to the home page
- Add a unique body class to the home page (to be used for styling)
- 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








































{ 0 comments… add one now }