Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to have different sidebars on different pages.

So firstly I registered a few basic sidebars in functions.php. So they will be always there no matter where I move my theme. Let's name them Standard Sidebar, Special Sidebar, Tiny Sidebar.

The next step was creating sidebars metabox below posts and pages. It lists all the sidebars using foreach $GLOBALS['wp_registered_sidebars'] loop and allows user to pick one.

Now, here comes the trouble.

I don't know how to display my sidebars.

I have a meta value but get_sidebar() accepts only names from sidebar.php file.

What about registered (not included in sidebar.php) sidebars?

I know I could add all my sidebars to sidebar.php/save them as sidebar-name.php, but again, I'm going to use sidebar generator to add addtional sidebars to three basic ones.

Any ideas, walk-troughs how to accomplish this? Displaying registered sidebars by name will be a serious breakthrough in my case.

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

You can call registered sidebars with the dynamic_sidebar() function. Just put the ID of the sidebar in to the call. In the case below the id would be homepage-sidebar.

<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('homepage-sidebar') ) : ?><?php endif; ?>
share|improve this answer
1  
dynamic_sidebar() is really old function by now, it's well time to stop checking if it exists. :) This just gets passed on as arcane spell... –  Rarst Apr 5 '11 at 17:30
    
fair enough I've just had the snippet stored for a while and haven't bothered to change it. –  curtismchale Apr 5 '11 at 20:05
    
Oh my God, I've been so blind ;/ In fact I found the same code @curtismchale gave in my own sidebar.php file... Just moved it from there to page.php... Thanks a lot guys, +1 :) –  Wordpressor Apr 5 '11 at 20:40
    
@Wordpressor rather than moving it to page.php you should stil call get_sidebar() and put your conditionals in sidebar.php. –  Chris_O Apr 6 '11 at 8:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.