WordPress – Different Sidebars In Different Places

It might, at some point in a WordPress powered blog, become necessary to a show some widgets/stuff in some places (the main page, archives, etc.) while show a different set of widgets/stuff in some other places (static pages – about me, product reviews, etc.). To keep track of things and may be understand the process better, let us suppose that only those pages written in Product Reviews Template will use a different sidebar (Sidebar #2) while rest of the blog uses a common sidebar (Sidebar #1). Thanks to my dear friend, Amy – if not for her, I probably would have never learned about this hack.

functions.php

Within the currently used WordPress theme, one can find functions.php. Backup this file before making the below given editions. At the very beginning of the file, one should see:

1
2
3
if ( function_exists('register_sidebar') )
    register_sidebar(array(
        'before_widget' => '
  • ‘,
    ‘after_widget’ => ‘

‘, ‘before_title’ => ‘

‘, ‘after_title’ => ‘

‘, ));

Change this to look like:

1
2
3
4
if ( function_exists('register_sidebar') )
    register_sidebar(array(
        'name' => 'Sidebar 1',
        'before_widget' => '
  • ‘,
    ‘after_widget’ => ‘

‘, ‘before_title’ => ‘

‘, ‘after_title’ => ‘

‘, )); register_sidebar(array( ‘name’ => ‘Sidebar 2’, ‘before_widget’ => ‘

  • ‘,
    ‘after_widget’ => ‘

‘, ‘before_title’ => ‘

‘, ‘after_title’ => ‘

‘, ));

This edit defines an additional sidebar. Save and close the file.

sidebar2.php

Within the currently used WordPress theme, one can find sidebar.php. Make a copy of this file and save it as sidebar2.php. One can edit the contents of sidebar2.php to place static content or use the Admin Dashboard to pick a certain set/ordering of widgets. For this particular case, I decided to leave it unchanged.

Product Reviews Template

Within the currently used WordPress theme, one needs to create a file called product_reviews.php, with the following contents:

1
2
3
<!--?php /* Template Name: My Product Reviews */ ?-->
 
<!--?php get_header(); ?-->

Writing Product Reviews

When writing product reviews, all that one needs to do – apart from writing the review itself – is to make sure to pick My Product Reviews as the Page Template. Such pages will have a different looking sidebar, owing to the above changes.

Screenshots

Selecting Widgets for Sidebar 1

Selecting Widgets for Sidebar #1

Selecting Widgets for Sidebar 2

Selecting Widgets for Sidebar #2

Sidebar 1

Sidebar #1

Sidebar 2

Sidebar #2