Top

Daily Tip: Select Sidebar on a Post-by-Post Basis Using Custom Fields

April 7, 2010

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:

< ?php get_sidebar(); ?>

Replace it with this:

<?php $sidebar = get_post_meta($post->ID, "sidebar", true);

get_sidebar($sidebar);
?>

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

Tweet This Post

Comments

Got something to say?

Bottom
Article Archive  |  This site is a historical archive of pressography.com, a WordPress plugin and theme blog that published between 2006 and 2012. It is preserved for reference and is not operated by, affiliated with, or endorsed by its original authors. Nothing here is for sale and no form on this site is active. If you are the original owner and would like this domain returned, please get in touch.