• Resolved sleeplessindc

    (@sleeplessindc)


    I understand that the Twenty Seventeen theme uses the sidebar on blog pages. I’d like it to also be used in non-blog pages. What do I need to add to the page template to include the sidebar? Or would it be a function that needs to be added for this?
    Thanks for your help.

Viewing 7 replies - 1 through 7 (of 7 total)
  • are you working with a child theme?

    if yes, create a folder /template-parts/ in the child theme, add a new file sidebar-page.php (the name is important as it is referred to in the functions).

    code for the sidebar-page.php file:

    <?php
    /**
     Template Name: Sidebar Page
     */
    
    get_header(); ?>
    
    <div class="wrap">
    	<div id="primary" class="content-area">
    		<main id="main" class="site-main" role="main">
    
    			<?php
    			while ( have_posts() ) : the_post();
    
    				get_template_part( 'template-parts/page/content', 'page' );
    
    				// If comments are open or we have at least one comment, load up the comment template.
    				if ( comments_open() || get_comments_number() ) :
    					comments_template();
    				endif;
    
    			endwhile; // End of the loop.
    			?>
    
    		</main><!-- #main -->
    	</div><!-- #primary -->
    	<?php get_sidebar(); ?>
    </div><!-- .wrap -->
    
    <?php get_footer();
    

    in functions.php of the child theme, add:

    add_filter( 'body_class', 'sidebar_page_body_classes', 12 );
    
    function sidebar_page_body_classes( $classes ) {
        if ( is_page_template( 'template-parts/sidebar-page.php' ) ) {
    		if( in_array('page-two-column', $classes) ) {
            	unset( $classes[array_search('page-two-column', $classes)] );
    			$classes[] = 'page-one-column'; 
    		}
    		$classes[] = 'has-sidebar'; 
        }
    	return $classes;
    }
    

    you can then select the new page template under page attributes when creating or editing a page.

    Thanks for this…I’ve been struggling with this all weekend. I still can’t get any widgets to appear in the static front page, or any sections added via Theme Options, although the content, including the section pages’ featured images, have moved over to the left to leave space for a right sidebar. There’s just nothing in that space. I’m using Widget Manager Lite to specify widget visibility, and it’s working on all pages except my static front page.

    I still can’t get any widgets to appear in the static front page, or any sections added via Theme Options, although the content, including the section pages’ featured images, have moved over to the left to leave space for a right sidebar.

    that was an untested unintended efffect – the front page is done via ‘front-page.php’ and I was not aware that the use of a page template for that page would make a difference.

    to fix this problem, the filter code for functions.php needs to be adjusted to:

    add_filter( 'body_class', 'sidebar_page_body_classes', 12 );
    
    function sidebar_page_body_classes( $classes ) {
        if ( is_page_template( 'template-parts/sidebar-page.php' ) && !is_front_page() ) {
    		if( in_array('page-two-column', $classes) ) {
            	unset( $classes[array_search('page-two-column', $classes)] );
    			$classes[] = 'page-one-column'; 
    		}
    		$classes[] = 'has-sidebar'; 
        }
    	return $classes;
    }

    @reneyoung
    if you try to have a sidebar on the front page, please create a new topic to ask your question.

    Thanks, but that didn’t change anything. All content below the first header image is still pushed to the left as if there’s a sidebar there.

    Thread Starter sleeplessindc

    (@sleeplessindc)

    I was just going to say the same thing about the front page. Everything is pushed to the left showing space for a sidebar but it is just empty space. It works fine on individual pages that were included in the front page but not when they are included in the front page. It works fine for all the other pages.

    Thread Starter sleeplessindc

    (@sleeplessindc)

    @alchymyth Thanks very much for the code for getting the sidebar on the pages! Very, very helpful.

    Thread Starter sleeplessindc

    (@sleeplessindc)

    I’ve created a new topic for getting the sidebar to show on the front page. This one for getting a sidebar for the static pages can be closed now. Thanks.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How do I get the side bar to also show on pages?’ is closed to new replies.