This document is deprecated! The information on this page refers to a Thesis version that is now obsolete. Please visit the Thesis Docs for current documentation.
Do you have two sidebars showing on your site by default, but wish you could only show one of them on a particular page? Thesis provides you with certain filters which make this a cinch!
There are four basic steps to making this happen:
- Remove the original sidebars from the page
- Restore sidebar 1 to the page
- Add a unique body class to the 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!