John LeschinskiHow to add an extra sidebar

Say your theme only has one sidebar.php and you want to have a different sidebar on your index then on your archives page. Adding extra sidebars is surprisingly easy and this is how to do it.

First we’ll create the sidebars. You can copy your current sidebar file and rename it to something like sidebar_two or sidebar_archives, almost anything you want really. If you decide to create it from scratch and want to maintain the widgets functionality of your theme be sure to include <?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar(2) ) : else : ?> <?php endif; ?> in the file where you wish the widgets to appear.

Next we tell Wordpress you have two sidebars. Your theme may already have a file called functions.php, but if it does not go ahead and create that file with notepad and include the following bit of code <?php if ( function_exists('register_sidebars') ) register_sidebars(2); ?> and put it in the theme folder. If you want to increase the number of sidebars just change the number in register_sidebars(2); to the number of sidebars you desire.

If your theme already has a functions.php file, open it up and look for register_sidebar.If it exists add register_sidebars(2); at the end of it, or you can try replacing the whole thing with the code given previously.

So we have told Wordpress how many we want, and have created the required sidebar files, now we just have to place them into our template. Open the file you wish the specific template to appear and add <?php include (TEMPLATEPATH . '/sidebar_two.php'); ?> or whatever you’ve named the file.

Now login to your admin, go over to your widget management tab, and you should see the sidebars listed there which you can now drag and drop the desired widgets into.

Voila!

John Leschinski Written by John Leschinski from Leschinski Design
Posted on August 16th, 2008 and filed under WordPress Coding & Design
Do not forget to subscribe to our RSS feed for updates
  • Digg This Post
  • Tweet This Post
  • Stumble This Post
  • Submit This Post To Delicious
  • Submit This Post To Reddit
  • Submit This Post To Mixx
  • BloggingTips Uses Aweber

4 Responses to “How to add an extra sidebar”

Author comments are in a darker gray color for you to easily identify the posts author in the comments

  1. EL Locco says:

    Nice article, I will try to implement that soon. Thanks

  2. Amaterashu says:

    I’m bad at coding like that, can you make the plugin for it??
    tell me if you can.. I’ll be waiting for it :wink:
    thankss..

  3. It’s simple enough that I don’t think it needs a plugin. Give it a try.

  4. ladytomorrow says:

    Hi…. thanks so much for your help!

Trackbacks

Comments are closed.

Comments are closed since this post is older than 30 days. However, you can continue this discussion in our popular Blogging Forums

Subscribe To BloggingTips Via RSS Subscribe To Blogging Tips Via Email Follow Us On Twitter Follow us on Facebook Find Out More About Our Newsletter

Sponsors

Blogging Tips Newsletter

Webmaster Corner

 

Our Free E-Books

Site Partners