0

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!

3

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.

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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