Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Environment: WP 3.5, Twenty Twelve child theme. I created a custom template. Now, I'd like to display the built-in sidebar-2 in this custom template 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 this custom template I created a file sidebar-customtemplate.php in my child theme directory with this content:

<?php if ( is_active_sidebar( 'sidebar-2' ) ) : ?>
    <div id="secondary" class="widget-area" role="complementary">               
        <?php dynamic_sidebar( 'sidebar-2' ); ?>
    </div><!-- #secondary -->
<?php endif; ?>

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

share|improve this question

4 Answers 4

Did you create a CSS that includes both left and right side bars?

/*----------------------------------------------------
    2 sidebars
---------------------------------------------------- */
#sidebar {
    Float:left;
    width:20%;
    display:block;
}
#sidebar-core {
    margin-right:20px;
}
#main {
    float: left;
    width: 65%;
    display: block;
}
#intro,
#main-core {
    margin-right: 20px;
    margin-left: 20px;
}
#sidebarright {
    display: block;
    float: left;
    width: 15%;
}
#sidebarright-core {
    margin-left: 20px;
}

Upload this in your styles in your theme. Name it something like two-sidebars.css, then go to your functions.php and require this once. You will have to define the path, an example is like this:

wp_register_style( 'twosidebars', get_template_directory_uri() . '/styles/layouts/two-sidebar.css', '', '1.1' );

You will see the other sidebar options for requirements. Model what you do off that.

Now you will need a new sidebar.php that calls the CSS, so create a new one and name it something like sidbar2.php and insert something like this:

<div id="sidebar">
        <div id="sidebar-core">    
            <?php do_action( 'before_sidebar' ); ?>
            <?php if ( ! dynamic_sidebar() get_sidebar() ); ?>   
        </div>
</div><!-- #sidebar -->

<div id="sidebarright">
        <div id="sidebarright-core">
            <?php do_action( 'before_sidebar' ); ?>
            <?php if ( ! dynamic_sidebar() get_sidebar(sidebar2) ); ?>   
        </div>
</div><!-- #sidebar2 -->

Now all of this assumes you have already registered the array sidebar2 as an array in your functions.php. This also assumes you edited your stylesheet to include a separate style for sidebar2.

share|improve this answer

Rename that sidebar-2 into sidebar-sidebar2.php and after use this code

<?php get_sidebar('sidebar2');?>

hope its may work

share|improve this answer
up vote 0 down vote accepted
<?php get_sidebar( 'customtemplate' ); ?> 

did the thing :)

share|improve this answer

you can put this code in your functions

add_action( 'init', 'register_my_menus' );
function register_my_menus() {
    register_nav_menus(
        array(
            'menu-1' => __( 'Head' )
        )
    );
}

and this code, in the place you want your second menu

<?php wp_nav_menu( array( 'theme_location' => 'menu-1' ) ); ?>

and than, you can control your new menu, through the menu section in the admin panel

share|improve this answer
    
Uhm, no. I don't need to register a menu. I need to use the already registered by default (in twenty twelve) "sidebar-2" in a custom template page. –  MultiformeIngegno Dec 23 '12 at 15:31
    
Oh, sorry, i didnt noticed. did you check if its passing the if condition? –  Iliya Reyzis Dec 23 '12 at 15:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.