Many a times you need a different set of widgets for different pages/sections of a site. Having a new sidebar specifically for that page/section would be ideal in such a situation. This can be easily done in wordpress. Heres how.
Theres two part to the whole thing. First, we need to create a new sidebar and second, we need to use the sidebar for a specific page.
To create a new sidebar , go to Appearance -> Editor -> Functions.php. There you already must be having something like:
if ( function_exists('register_sidebar') )
{
register_sidebar(array('name'=>'Sidebar 1','before_widget' => '<div class="widget">','after_widget' => '</div>','before_title' => '<h4>','after_title' => '</h4>',));
}
Add these lines in between (remember : before } of last line), it will create another sidebar, “Sidebar 2”
register_sidebar(array('name'=>'Sidebar 2','before_widget' => '<div class="widget">','after_widget' => '</div>','before_title' => '<h4>','after_title' => '</h4>',));
So Finally it would look like :
if ( function_exists('register_sidebar') )
{
register_sidebar(array('name'=>'Sidebar 1','before_widget' => '<div class="widget">','after_widget' => '</div>','before_title' => '<h4>','after_title' => '</h4>',));
register_sidebar(array('name'=>'Sidebar 2','before_widget' => '<div class="widget">','after_widget' => '</div>','before_title' => '<h4>','after_title' => '</h4>',));
}
So “Sidebar 2″ is now created. Now you need to create a sidebar2.php page and upload it to your wordpress theme folder.
Sidebar2.php should be a replica of sidebar.php (which is in your theme folder). It all depends on the theme you are using and how it is setup, so this part will be different for different blogs. but the basic idea is to create a similar page but with the changes that you want in the new sidebar.
So if your Sidebar.php has this part :
<?php global $wp_theme_options; ?>
<div class="w300- sidebar">
<!--sidebar.php-->
<?php if ( !function_exists('dynamic_sidebar')
|| !dynamic_sidebar('Sidebar 1') ) : ?>
Your sidebar2.php should have : (notice the two changes)
<?php global $wp_theme_options; ?>
<div class="w300- sidebar">
<!--sidebar2.php-->
<?php if ( !function_exists('dynamic_sidebar')
|| !dynamic_sidebar('Sidebar 2') ) : ?>
Use any ftp client you like (i prefer FileZilla) and go to public_html/wp-content/themes/your-theme and upload it there. set permission to 744.
Now we have set sidebar2.php to be the dynamic sidebar which we can use for any section we want. This post is getting longer , so we will do that in the next post.
Let me know if you have any other easier way of doing this. plus, if you have some prob doing this let me know.
Related:






September 23rd, 2009 at 12:13 pm
Very useful article. Eagerly awaiting for the follow-up post.