Different widgets on different page templates?

You will need to create more sidebars in your functions.php file and then edit the page templates to call the sidebar you want.

Adding sidebars

Go in to your functions.php file. You should see some sidebars already being registered. The code will look something like this:

//Adds default sidebar
 if ( function_exists('register_sidebar') )
 register_sidebar();

To add another sidebar, add the following code any number of times after the existing sidebar registration.

//Registers new sidebar
if ( function_exists('register_sidebar') ) {
    register_sidebar(array('name' => 'Name Sidebar Here','before_widget' => '','after_widget' => '','before_title' => '<h2 class="widgettitle">','after_title' => '</h2>'));    
} 

Where it says ‘Name Sidebar Here’ put a logical name for this new sidebar. The rest of the array allows you to put HTML before the widget (before_widget) if your theme requires that for its design and put HTML after the widget (after_widget). Also, more commonly used in themes is a custom style for widget titles. You can put that HTML before the title (before_title) and after the title (after_title). In the example above, each widget title will have <h2 class="widgettitle"> placed before it and after it to close the opening tag.

Add your new sidebar to your page templates

Now that you’ve added a sidebar, you’ll need to put it in the page template where you want it. Find where the default sidebar is being called inside of your template ( usually ) and replace it with the following, where the number is the order of where the sidebar was added in functions.php file.

<?phpif ( !function_exists('dynamic_sidebar') || !dynamic_sidebar(Sidebar number here) ) : ?><?php endif; ?>

This sidebar was the second one added in the functions.php file, so to call it in the page template, you’ll put 2 inside of !dynamic_sidebar(Put sidebar number here) ).

Add widgets

Once you’ve added it to the page template, just add widgets to the sidebar in your Appearance–>Widgets administration page. The new sidebar will appear there with the name you gave it in the functions.php file.

Hope this helps!

Leave a Comment