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.

I registered a few custom sidebars, and the corresponding code in my version of TwentyTwelve theme now looks like this:

    register_sidebar( array(
    'name' => __( 'Sidebar #1', 'twentytwelve' ),
    'id' => 'sidebar-1',
    'description' => __( 'Appears on posts and pages except the optional Front Page template, which has its own widgets', 'twentytwelve' ),
    'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    'after_widget' => '</aside>',
    'before_title' => '<h3 class="widget-title">',
    'after_title' => '</h3>',
) );

register_sidebar( array(
    'name' => __( 'Sidebar #2', 'twentytwelve' ),
    'id' => 'sidebar-2',
    'description' => __( 'Appears on posts and pages except the optional Front Page template, which has its own widgets', 'twentytwelve' ),
    'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    'after_widget' => '</aside>',
    'before_title' => '<h3 class="widget-title">',
    'after_title' => '</h3>',
) );

register_sidebar( array(
    'name' => __( 'Sidebar #3', 'twentytwelve' ),
    'id' => 'sidebar-3',
    'description' => __( 'Appears on posts and pages except the optional Front Page template, which has its own widgets', 'twentytwelve' ),
    'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    'after_widget' => '</aside>',
    'before_title' => '<h3 class="widget-title">',
    'after_title' => '</h3>',
) );

register_sidebar( array(
    'name' => __( 'Sidebar #4', 'twentytwelve' ),
    'id' => 'sidebar-4',
    'description' => __( 'Appears on posts and pages except the optional Front Page template, which has its own widgets', 'twentytwelve' ),
    'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    'after_widget' => '</aside>',
    'before_title' => '<h3 class="widget-title">',
    'after_title' => '</h3>',
) );

register_sidebar( array(
    'name' => __( 'Sidebar #5', 'twentytwelve' ),
    'id' => 'sidebar-5',
    'description' => __( 'Appears on posts and pages except the optional Front Page template, which has its own widgets', 'twentytwelve' ),
    'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    'after_widget' => '</aside>',
    'before_title' => '<h3 class="widget-title">',
    'after_title' => '</h3>',
) );

My custom page template uses #sidebar-1:

<div id="inner-page-sidebar">

<?php get_sidebar(); ?>

</div> <!-- END INNER-PAGE-SIDEBAR -->

Now I want to create a separate custom page template # 2, which should be identical to custom page template # 1, except it should use #sidebar-2 instead of #sidebar-1.

Question: How should I place the alternative sidebar there?

Thank you in advance for your help!

share|improve this question

2 Answers 2

up vote 3 down vote accepted

Instead of calling get_sidebar() call get_sidebar( 'somethingelse' );. It will attempt to load sidebar-somethingelse.php and if that doesn’t exist it will load sidebar.php. You can then modify the sidebar-somethingelse.php to load a different sidebar etc

I strongly recommend you look up how the template hierarchy works.

share|improve this answer
    
Thank you, it worked, of course! –  Astoria Apr 24 '13 at 18:47

look in the sidebar pages that are in the template. All the code you need is already there. You will see something like

  if( is_active('sidebar-1')){
      get_sidebar('sidebar-1');
  }

I am not sure of the exact code as I am not sitting at my computer with the files. ALL you need to do is copy that code and change the names to match your sidebar. There are a few pages that you can look in. Like sidebar.php, front-page.phhp that is in the templates directory. That should call a sidebar or two.

share|improve this answer

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.