Select Sidebar on a Post-by-Post Basis Using Custom Fields

Select Sidebar on a Post-by-Post Basis Using Custom Fields

If you’ve every wanted to use different sidebars for different post categories or even individual posts, here’s a quick and easy way to put a little more customization into your templates. Open your single.php file and locate the sidebar:

{code type=php}
< ?php get_sidebar(); ?>
{/code}

Replace it with this:

{code type=php}
ID, “sidebar”, true);
get_sidebar($sidebar);
?>
{/code}

Now when you want to use a different sidebar, you’ll simply create a custom field called “sidebar.” Give it the value of the custom sidebar templates you’ve created- for example: sidebar-news.php, sidebar-full.php, sidebar-photos.php. If you want to use your news sidebar, give the custom field the name “sidebar” and the value “sidebar-news”.

Source: SpryeStudios.com