Adding Another Sidebar to Wordpress
I'm using Wordpress 2.7 at the time of writing, but my theme is modified from the default theme from around version 2.5. My current sidebar uses the widgets feature with some manually added stuff, sort of a lazy way of customizing it. I keep adding to it and now I need a second one, which will inevitably require a wider site but my analytics shows most people these days have more than the formerly standard 1024x780 screen resolution and so it should be fine.
So if you're in the same boat as me, hand me that paddle, I'll show you what I did.
In your theme folder open your functions.php file, and find the following code:
if ( function_exists('register_sidebar') ) register_sidebar(array( 'before_widget' => '<li id="%1$s" class="widget %2$s">', 'after_widget' => '</li>', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>', ));You may not have the above code, instead look for:
if ( function_exists('register_sidebar') ) register_sidebar();In either case we want to replace it with the following:
if ( function_exists('register_sidebars') ) register_sidebars(2);Note: changed sidebar to sidebars, and the number 2 indicates the total sidebars we want. In your theme folder open your index.php file, and find the following code:
<?php get_sidebar(); ?>Or depending on your theme:
<?php include(TEMPLATEPATH."/sidebar.php");?>Since I want to add another right sidebar, add the following code below:
<?php get_sidebar('2'); ?>Note: Anything between the ' ' is representative of the new file you have to create called in this case sidebar-2.php Or in the later case for consistency you can instead add:
<?php include(TEMPLATEPATH."/sidebar-2.php");?>The call for your sidebars in your index.php file should now look something like the following:
<div id="sidebar"> <?php get_sidebar(); ?> <?php get_sidebar('2'); ?> </div>In my case since I already had a sidebar, the "sidebar" div was inside sidebar.php. As you can see from the code above, it needs to be in the index.php file. Change the div id in sidebar.php to "sidebar1", and in sidebar-2.php to "sidebar2". Note: At this point you should see the two sidebars, and be able to add widgets or custom php. But it will likely appear below the other sidebar. Since I have css rules for sidebar, and not sidebar1 or 2, I can just re-assign some of the rules to sidebar 1, create a similar set for sidebar two and adjust the overall body and content width. This all depends on your theme and where you want your new sidebar.



January 6th, 2009 at 4:18 pm
[...] [...]