I am building a site in WordPress. It has multiple subpages, many of which require different sidebars. So, I have a widgetized theme and I have also created a few sidebar widgets.
I have written a conditional statement to show different sidebars on different pages. However, one widgetized sidebar displays on almost all pages despite the conditional statement.
The sidebar that is appearing on the desired page can be seen here: http://www.africanhealthleadership.org/about/approach/
The subpage that should have a different sidebar is under Knowledge Resources>Research
The code is as follows. I am a total PHP spazz, so I likely did something silly. I have tried single quotes around dynamic_sidebar(2) but that did not work.
Thank you for any help.
<?php
if ( is_subpage('approach') ) {
if (!function_exists ( dynamic_sidebar(1) ) ) ;
}
elseif ( is_subpage('research')) {
if (!function_exists( dynamic_sidebar(2)) || !dynamic_sidebar( "Sidebar2") );
}
?>
More easy & elegant (higher maintainability):
I don’t know why anybody checks whether
dynamic_sidebar
exists. It’s been around for 9 major releases now. I really hope you’re not developing for 2.1 or lower. Try this:If you know the specific page you want to use, don’t bother with that subpage junk. Besides, that function only checks if you’re on a subpage in general, but it won’t tell you if you’re on a specific subpage.
You could just use “Widget Logic” extension so you don’t need write support for custom widgets in sidebar into the actual template.