So let’s say you run into a situation like this. You are running a Wordpress site that needs more than 1 sidebars that are content manageable through the Wordpress admin interface using the ‘Wordpress Widgets’. I recently ran into a snag where I needed to find a solution in this area. It’s actually pretty easy. Let’s take a look at how to accomplish this.
Making A Wordpress Theme Widget Enabled
Basically, your theme’s functions.php file is the file that controls whether or not your Wordpress theme is “widget enabled”. Many themes already contain this file, and many do not. So if yours does not you just need to create it. Here is what you would need to put in your functions.php file in order to make your theme “widget enabled”…
<?php
if ( function_exists('register_sidebar') )
register_sidebar();
?>
Next you need to put some php code inside your sidebar.php file in order for you to actually show the widgets on your Wordpress blog. Located your Sidebar.php file and place this code in your desired location.
<?php if ( !function_exists('dynamic_sidebar')
|| !dynamic_sidebar() ) : ?>
<?php endif; ?>
Now your wordpress theme ( if it by chance was not already ) is widget enabled and can actually utilize the Wordpress Widget technology. That is the first step that must be covered.
Setting up Multiple Widget Enabled Sidebars
Now to the good stuff. Now we want to create more of these. If you noticed, in your administration interface under Design you now have a widgets section where you can manage your widgets for your sidebar. But we need to create more of these. Here’s how we do it. Go back to your functions.php file and input the following…
<?php
if ( function_exists('register_sidebar') )
register_sidebar(array('name'=>'sidebar1',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h4>',
'after_title' => '</h4>',
));
register_sidebar(array('name'=>'sidebar2',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h4>',
'after_title' => '</h4>',
));
?>
You can just continue repeating this code over and over to cover however many dynamic widget sidebars that you need. Once you are done with this, next you need to input some code in your sidebar.php file to actually present these new widget sidebars that you have created. Do this…
Sidebar1 code goes like this
<?php if ( !function_exists('dynamic_sidebar')
|| !dynamic_sidebar('sidebar1') ) : ?>
<?php endif; ?>
Sidebar2 code goes like this
<?php if ( !function_exists('dynamic_sidebar')
|| !dynamic_sidebar('sidebar2') ) : ?>
<?php endif; ?>
And on and on. You can use some simple PHP if else statements to put specific sidebars on specific pages. For example, you may want to place sidebar1 on only the homepage, and sidebar2 on the rest of the pages but not the homepage. Here’s the code I put together to accomplish this…
<?php
if (is_home()|| is_page()) {
echo wpads(’adFill’);
( !function_exists(’dynamic_sidebar’) || !dynamic_sidebar(’sidebar1′) );
} else {
echo wpads(’adFill’);
( !function_exists(’dynamic_sidebar’) || !dynamic_sidebar(’sidebar2′) );
echo wpads(’SADF’);
}
?>
That’s it! You now have multiple widget enabled sidebars running on your wordpress blog. This gives your site much more flexibility in design and functionality and can really enhance the content that you deliver to your visitors. Now you can go to your wordpress admin interface and you will see all your widget sidebars in a dropdown menu where you can drag and drop items to and from each specific sidebar. Good luck and have fun with this!








Entries (RSS)