Sunday, March 16, 2008

Adding a 3rd sidebar

I've begun adding a 3rd sidebar to my theme as a first step towards figuring out how to add widgets outside of sidebars. While it took me an hour or two to figure this out, the solution is quite simple. This post helped a lot.

  1. Duplicate sidebar.php within your theme folder. This will become your new sidebar.
  2. Remove all code between the php if function_exists tags. Also remove all except one li block (having class=widget)
  3. So far your code might look like this:
    1. <div id="new_sidebar">
      <ul class="sidebar_list">
      <?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar(1)) : ?>
      <li class="widget">
      <h2>Blah</h2>
      <ul>
      Blah Blah
      </ul>
      </li>
      <?php endif; ?>
      </ul>
      </div>

  4. Next you will need to change two parameters so that wordpress knows it is looking for 3 (or more) sidebars each with an id 1-3
    1. First you will need to change the id parameter of the dynamic_sidebar function on each sidebar.php file for example you can see that the dynamic_sidebar function below has a parameter of 1 ... thus this sidebar.php file should relate to sidebar id 1 ... each sidebar.php should have a different integer here from 1-3 (for three sidebars)

      1. <?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar(1)) : ?>
    2. Next we will change the parameter of the register_sidebars function (which is normally in functions.php but may be elsewhere in your wp install) to 3 (since we have three sidebars to register)
      1. register_sidebars(3);

No comments: