Skip to content

Instantly share code, notes, and snippets.

@derick-montague
Created August 11, 2012 03:13
Show Gist options
  • Save derick-montague/3320298 to your computer and use it in GitHub Desktop.
Save derick-montague/3320298 to your computer and use it in GitHub Desktop.
Function for wordpress to determine whether to show sidebar based on page id
// Need to reset the wordpress query before running
wp_reset_query();
$i = true;
switch($i) {
case (is_front_page()):
$i = false;
break;
case (is_page('contact-us')):
$i = false;
break;
default:
$i = true;
break;
}
if ($i) include('sidebar.php');
$side_bar = '';
$i = true;
switch ( $i )
{
case is_page('page-slug'):
$side_bar = 'sidebar_name';
break;
case is_page('page-slug'):
$side_bar = 'sidebar_name';
break;
case is_page('page-slug'):
$side_bar = 'sidebar_name';
break;
case is_page('page-slug'):
$side_bar = 'sidebar_name';
break;
}
// If the sidebar has not been named, use the generic sidebar
if ($side_bar == '')
{
dynamic_sidebar();
}
// Otherwise use the custom one for the specific page
else
{
dynamic_sidebar($side_bar);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment