WordPress Multiple Sidebars

Posted in: - Mar 12, 2011 1 Comment
// Registering Multiple Sidebars in functions.php

// Starting Sidebar Registering Function

if ( function_exists('register_sidebar') ) {

// Registering First Sidebar as Default Sidebar

	register_sidebar(array('name'=>'Sidebar',
		'before_widget' => '<div>',
		'after_widget' => '</div>',
		'before_title' => '<h3>',
		'after_title' => '</h3>',
	));

// Registering Second Sidebar for specific page like Blog

	register_sidebar(array('name'=>'Sidebar-Blog',
		'before_widget' => '<li>',
		'after_widget' => '</li>',
		'before_title' => '<h3>',
		'after_title' => '</h3>',
	));
}

Here we have registered two different sidebars for different pages and different widgets handling in it.


// This is the code in Sidebar-Blog.php file.
<div id="sidebar-blog">
	<?php if ( !dynamic_sidebar('Sidebar-Blog') ) : ?>
	<?php endif; ?>
</div><!--end of sidebar div-->

For getting sidebar on page where we want it we use this code.


// Getting sidebar template on specific page that we created in function.php
get_template_part('Sidebar-Blog');

I hope this will help.
Thanks

One Response

  1. comment writer
    Reply C.M. Wilson says:

    Thank you! This works perfectly. Your tips are really helpful.

Trackbacks

Leave a Reply