WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Showing sidebar-2 on home page only (4 posts)

  1. MultiformeIngegno
    Member
    Posted 1 year ago #

    Environment: WP 3.5, Twenty Twelve child theme. I created a custom template, set a page to use it and set it as home page.
    Now, I'd like to display the built-in sidebar-2 in home page (instead of the default sidebar-1). sidebar-2 is already registered by twenty twelve functions.php.
    I read a bit about get_sidebar and how to activate other sidebars, but I'm still a bit confused.
    To activate sidebar-2 on home page I created a file sidebar-homepage.php in my child theme directory with this content:

    <?php if ( is_active_sidebar( 'sidebar-2' ) ) : ?>
    		<div id="secondary" class="widget-area" role="complementary" style="float:left">
    				<nav id="site-navigation" class="main-navigation" role="navigation">
    			<h3 class="menu-toggle"><?php _e( 'Menu', 'twentytwelve' ); ?></h3>
    			<a class="assistive-text" href="#content" title="<?php esc_attr_e( 'Skip to content', 'twentytwelve' ); ?>"><?php _e( 'Skip to content', 'twentytwelve' ); ?></a>
    			<?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'nav-menu' ) ); ?>
    		</nav><!-- #site-navigation -->
    			<?php dynamic_sidebar( 'sidebar-2' ); ?>
    		</div><!-- #secondary -->
    	<?php endif; ?>

    Then in my homepage.php (custom template) I replaced get_sidebar(); with <?php get_sidebar( $homepage ); ?>. Then I added some widgets to the sidebar-2 (from Appearance - Widget), but in the home page still sidebar-1 is displayed! Why? :(

  2. MultiformeIngegno
    Member
    Posted 1 year ago #

    Probably the menu stuff can be misunderstood, let's remove it and assume that sidebar-homepage.php is:

    <?php if ( is_active_sidebar( 'sidebar-2' ) ) : ?>
        <div id="secondary" class="widget-area" role="complementary">
            <?php dynamic_sidebar( 'sidebar-2' ); ?>
        </div><!-- #secondary -->
    <?php endif; ?>
  3. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    unless you have set the variable $homepage to hold the value 'homepage', try:
    <?php get_sidebar( 'homepage' ); ?>

  4. MultiformeIngegno
    Member
    Posted 1 year ago #

    Thanks!! That was the problem! I already used the variable $homepage. I changed it to home and it worked :)
    Thank you!

Topic Closed

This topic has been closed to new replies.

About this Topic