large shade tree



Recent Posts

Shade Tree Sites |Building Better Websites

Create a Custom Sidebar for Posts and Pages

Tired of seeing the same old sidebar on every post in your blog or website here’s a way to create custom sidebar configurations and choose which to display on every post or page.

To display a custom sidebar for a post or page try this:

First create your new sidebar file, name it sidebar-yournamehere.php and upload into your theme folder.
Easiest way to do this is copy your existing sidebar.php file, make your modifications and save with your new name.

In your single.php and/or page.php template replace:

<?php get_sidebar(); ?> 

With this:

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

The above code simply creates a new post meta field called sidebar and tells WordPress to look for a custom field called sidebar and if there is one to use the sidebar specified in that field.

Then when writing a post or page go to the custom field area, create a new custom field name it:   sidebar   then in the value field write   yournamehere   (the name of the new custom sidebar you created earlier or an existing custom sidebar you already created) – this will call the file sidebar-yournamehere.php for that post or page.

That’s it.