• Resolved Tamara

    (@heyitstamara8)


    Hi there,

    I’ve just generated a theme using underscores and am trying to figure out why my sidebars aren’t showing up. . .

    I have registered 2 sidebars in my functions file like so:

    function creativeandcurlyv5b_widgets_init() {
    	register_sidebar( array(
    		'name'          => esc_html__( 'Primary Sidebar', 'creativeandcurlyv5b' ),
    		'id'            => 'sidebar-1',
    		'description'   => '',
    		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    		'after_widget'  => '</aside>',
    		'before_title'  => '<h2 class="widget-title">',
    		'after_title'   => '</h2>',
    	) );
    
    	register_sidebar( array(
    		'name'          => __( 'Front Page Sidebar', 'creativeandcurlyv5' ),
    		'id'            => 'sidebar-2',
    		'description'   => '',
    		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    		'after_widget'  => '</aside>',
    		'before_title'  => '<h2 class="widget-title">',
    		'after_title'   => '</h2>',
    	) );
    
    }
    add_action( 'widgets_init', 'creativeandcurlyv5b_widgets_init' );

    . . . and then chose to do an if else on several of my theme files (index, archive, page, search), which in retrospect probably doesn’t really make much sense at all :

    <!-- MULTI SIDEBARS -->
    <?php
    if ( is_front_page() ) {
        // This is the front page index, display the regular sidebar
        get_sidebar( 'Front Page Sidebar' );
    } else {
        // This is not the front page, display the regular sidebar
        get_sidebar();
    }
    ?>
    <!-- END MULTI SIDEBARS -->

    I was considering making a homepage / front page template, (making no need for the multi sidebar if/else statements on all of those templates) but I was a tad confused with how wordpress differentiates between is_home() and is_front_page() . . . on my blog, the homepage is the 5 or so most recent posts, not a static page.

    Any help anyone can lend here would be greatly appreciated!

    Thanks,
    Tamara

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Tamara

    (@heyitstamara8)

    Do I need to encorporate something like this??

    is_front_page() && is_home() // Default homepage

    for this line:
    get_sidebar( 'Front Page Sidebar' );

    do you have a file sidebar-Front-Page-Sidebar.php in your theme?

    https://codex.www.ads-software.com/Function_Reference/get_sidebar

    you might need to create and call a suitably named sidebar file which uses
    dynamic_sidebar( 'Front Page Sidebar' )

    https://codex.www.ads-software.com/Function_Reference/dynamic_sidebar

    Thread Starter Tamara

    (@heyitstamara8)

    I have a sidebar-2.php file:

    <?php
    /**
     * The sidebar containing the front page widget area.
     *
     * @package Creative & Curly - v5b
     */
    
    if ( ! is_active_sidebar( 'sidebar-2' ) ) {
    	return;
    }
    ?>
    
    <div id="secondary" class="widget-area" role="complementary">
    	<?php dynamic_sidebar( 'sidebar-2' ); ?>
    </div><!-- #secondary -->
    Thread Starter Tamara

    (@heyitstamara8)

    I am forgoing this idea doing regular single sidebars on every page.

    Then I am going to try and create another template file just for the homepage, where I can call that sidebar.

    Thread Starter Tamara

    (@heyitstamara8)

    Update, I fixed this myself, but realized I did indeed need to take your advice – alchymyth, so thank you!!

    1) I renamed sidebar-2.php
    —> It is now named sidebar-home.php

    2) I changed my multi-sidebar code in all of my template files to be like so:

    <!-- MULTI SIDEBARS -->
    <?php
    if ( is_front_page() && is_home() ) { // Default homepage
    	get_sidebar( 'home' );
    } elseif ( is_front_page() ) { // static homepage
    	get_sidebar( 'home' );
    } elseif ( is_home() ) { // blog page
    	get_sidebar( 'home' );
    } else { //everything else
    	get_sidebar();
    }
    ?>
    <!-- END MULTI SIDEBARS -->

    Then all of a sudden my homepage / frontpage sidebar started showing up on the homepage ??

    So it was definitely renaming my sidebar file to match with what I was putting in the template files. Thank you again!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Multiple sidebars – showing up in widget area but not on live site’ is closed to new replies.