Creating Multiple Widget Sidebars for WordPress
If you have multiple sidebars, or multiple themes with multiple sidebars, itâs a good idea to use dynamic sidebars. WordPress Widgets (WPW) is like a plugin, but designed to provide a simple way to arrange the various elements of your sidebar content (known as âwidgetsâ) without having to change any code. Whatâs nice about using widgets is theyâre easy to use and you have the contents of all your sidebars on one page so theyâre easier to edit. When using different layouts with the same sidebar contents, all you need to do is call the sidebar functions to get the contents. If you want to insert php in your sidebar, thereâs a plugin called PHP Exec. Click on that link and scroll down to where it says execphp.zip, and download it.
In order to use widgets, you need to place this bit of code in your sidebar.php or whatever your sidebar page is:
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('graphics') ) : ?>
<?php endif; ?>
Where it says âgraphicsâ, replace it with whatever your sidebar name is mentioned in functions.php below.
Youâll need to make sure you have a functions.php in your theme folder. Inside functions.php, put this:
<?php
if ( function_exists('register_sidebar') )
register_sidebar(array('name'=>'journal',
'before_widget' => '<div id="sidebar">', // Removes <li>
'after_widget' => '</div>', // Removes </li>
'before_title' => '<p class="navi">', // Replaces <h2>
'after_title' => '</p>', // Replaces </h2>
));
register_sidebar(array('name'=>'about',
'before_widget' => '<div id="sidebar">', // Removes <li>
'after_widget' => '</div>', // Removes </li>
'before_title' => '<p class="navi">', // Replaces <h2>
'after_title' => '</p>', // Replaces </h2>
));
register_sidebar(array('name'=>'archive',
'before_widget' => '<div id="sidebar">', // Removes <li>
'after_widget' => '</div>', // Removes </li>
'before_title' => '<p class="navi">', // Replaces <h2>
'after_title' => '</p>', // Replaces </h2>
));
register_sidebar(array('name'=>'gallery',
'before_widget' => '<div id="sidebar">', // Removes <li>
'after_widget' => '</div>', // Removes </li>
'before_title' => '<p class="navi">', // Replaces <h2>
'after_title' => '</p>', // Replaces </h2>
));
register_sidebar(array('name'=>'graphics',
'before_widget' => '<div id="sidebar">', // Removes <li>
'after_widget' => '</div>', // Removes </li>
'before_title' => '<p class="navi">', // Replaces <h2>
'after_title' => '</p>', // Replaces </h2>
));?>
Make modifications where it says âjournalâ, âaboutâ, etc. Also you can chose different tags before where it shows comments such as //ReplacesâŠThe number of calls to register_sidebar depends on the number of sidebars you have.
Now when you go to wp-admin, under âPresentationâ, there should be a link to âWidgetsâ. From there you can drag boxes under âAvailable Widgetsâ onto a sidebar box. Some widgets allow you to edit the contents or settings. Click on the icon on the right of the widget box in a sidebar to see what you can edit. Click on the âXâ when youâre done editing. Donât forget to âSave Changesâ. To view changes, refresh your browser, or delete your cache and refresh again if you donât see the changes.