Choose which wordpress sidebar to use

September 26, 2009 · Print This Article

WordPress always have to display the same boring sidebar on each page? What can we do?

Don’t worry, just create a few sidebar files, upload it to your wordpress theme directory. Then the code follow will do the rest.

open single.php and find the call to the get_sidebar() function:

<?php get_sidebar(); ?>

Replace it by:

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

Now when you’ll write a post, create a custom field name sidebar. As a value, give it the name of the sidebar you want to include. For example, if the value given is livexp, WordPress will automatically inlcude live.php as a sidebar.

Note: The same can be done on page.php.


Your choice for site templates and wordpress themes

Comments

Got something to say?

You must be logged in to post a comment.