free quote
Excelnet Media LLC

How to Add a Second Sidebar to Your Wordpress Theme

This tutorial will cover how to add a second sidebar to your WordPress theme. This is very useful when you have a 3 column layout.

WordPress 2.5 introduced the name parameter to the include tag get_sidebar().

We are going to add a widgetized left sidebar and a widgetized right sidebar to a 3 column layout.

Step 1: Create 2 files, named sidebar.php and sidebar-right.php.

Code for sidebar.php

<?php
/**
Template Name: Sidebar
 */
?>
<div id="sidebar">
<ul>
<?php 	/* Widgetized sidebar, if you have the plugin installed. */
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
<?php endif; ?>
</ul>
</div>

The id of the sidebar can be anything you would like. The code between the php tags should not be changed.

Code for sidebar-right.php

<?php
/**
Template Name: Sidebar Right
 */
?>
<div id="sidebar-right">
<ul>
<?php 	/* Widgetized sidebar, if you have the plugin installed. */
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar Right') ) : ?>
<?php endif; ?>
</ul>
</div>

The id of the sidebar can be anything you would like. The code between the php tags should not be changed.

Step 2: Add the following to your template files where you would like your sidebars to display in your layout. The most template files are archive.php, category.php, index.php, page.php and single.php. The WordPress Codex has a tutorial on template pages and template hierarchy.

<?php get_sidebar(); ?>
<?php get_sidebar('right'); ?>

Step 3: Add this to your functions.php page.

<?php
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>',
    ));

    register_sidebar(array('name'=>'sidebar-right'
    ));

Below is what it should look like in your WordPress admin panel.
Widget Admin

Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Design Float
  • email
  • FriendFeed
  • LinkedIn
  • Netvibes
  • StumbleUpon
  • Twitter

Related Posts

  1. How to Create Multiple Widgetized Sidebars in WordPress
  2. How to Create Multiple Page Layouts Using One Page Template in WordPress

Comments

One Response to “How to Add a Second Sidebar to Your Wordpress Theme”
  1. Funkhero says:

    You should mention that the get_sidebar function searches for the filename of the sidebar –
    so, for a bar called foo, the file has to be called “sidebar-foo.php” !

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

Excelnet Media LLC