This tiny little problem is turning my hair grey.
May 26, 2010 9:00 PM   Subscribe

Help me figure out this Wordpress sidebar problem.

I want to have three widgetized sidebars on my site: one on the Homepage, a different one on the Blog page, and another on the Members page.

I altered my functions.php to register three sidebars.
I copied sidebar.php twice and renamed them sidebar2.php and sidebar3.php.
I created custom templates for the Blog and Members pages, and called their respective sidebars thusly:
include ('sidebar2.php');

In the Admin area under Widgets, there are three sidebars. I dragged a different set of widgets to each and saved.

On the live site, all three sidebars are identical. They each load the widgets from the first sidebar.

This post should invoke my universal law of coding: the minute I ask for help, I figure it out myself. But in case that doesn't work, your expertise is welcome!
posted by shopefowler to Computers & Internet (3 answers total) 4 users marked this as a favorite
 
A URL might help us here....
posted by pjern at 10:07 PM on May 26, 2010


Best answer: Don't make more files than you need, just include the one sidebar and do it with good conditionals.

Your registering of the sidebars should look like this inside functions.php:
if ( function_exists('register_sidebars') ):
	register_sidebar(array(
		'name' => 'for-home-page',
		'before_widget' => '',
		'after_widget' => '',
		'before_title' => '<h2>',
		'after_title' => '</h2>',
	));
	register_sidebar(array(
		'name' => 'for-blog-page',
		'before_widget' => '',
		'after_widget' => '',
		'before_title' => '<h2>',
		'after_title' => '</h2>',
	));
	register_sidebar(array(
		'name' => 'for-member-page',
		'before_widget' => '',
		'after_widget' => '',
		'before_title' => '<h2>',
		'after_title' => '</h2>',
	));
endif;
And then in your sidebar.php you would do. This assumes your members page has a slug of "members" see the Conditional Tags docs for other ways. Have the most common sidebar be the last one, your else condition.
<?php if (is_front_page()): ?>
	<?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar('for-home-page') ) : else : ?>
	<?php endif; ?>
<?php elseif (is_page('members')): ?>
	<?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar('for-member-page') ) : else : ?>
	<?php endif; ?>
<?php else: ?>
	<?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar('for-blog-page') ) : else : ?>
	<?php endif; ?>
<?php endif; ?>

posted by artlung at 10:14 PM on May 26, 2010 [1 favorite]


Response by poster: Worked perfectly - thanks!
posted by shopefowler at 10:30 PM on May 26, 2010


« Older How itchy is too itchy?   |   Calling police over loose dogs in a public park:... Newer »
This thread is closed to new comments.