Archived topic
Different sidebar layout for different blog post pages
4 replies · Started by Sharon Steely on October 5, 2015
I use the latest posts as my home page. I used the customizer to set the layout for Blog Sidebar Layout to Content (no sidebars) which is what I want for the home page.
For my archives and categories, I want the left sidebar to show. Since these aren't technically "pages" I don't see a way to edit to turn off global settings.
Here is my home page currently:
http://elnews-new.unm.edu/
Here is a category page, which I want to display with the left sidebar:
http://elnews-new.unm.edu/index.php/category/online/
This is a dev site.
Thanks for your help!
Hi Sharon. You could set the default layout to left sidebar, then use this function in your child theme functions.php file to remove the sidebar on your home page:
add_filter( 'generate_sidebar_layout','generate_custom_sidebar_layout' );
function generate_custom_sidebar_layout( $layout ) {
// If we are on the home page, no sidebar
if ( is_home() )
return 'no-sidebar';
// Or else, set the regular layout
return $layout;
}
Adding PHP: https://generatepress.com/knowledgebase/adding-php-functions/
Thanks bdbrown! I just implemented your suggestion and it worked!
I appreciate you sharing the code as-is. My knowledge of pHP is very limited.
Thanks for your help!
And thanks for writing an awesome theme Tom!
Glad to help :) If you're interested in learning more about PHP, here are a couple of good tutorials to get you started:
http://www.webmonkey.com/2010/02/php_tutorial_for_beginners/
http://devzone.zend.com/6/php-101-php-for-the-absolute-beginner/
cool, thanks.
