I just learned (with help from Rob Vermeer!) how to use one template and be able to call different top graphics depending on the page and now I want to know if the following is possible:
I'm using the page.php (default template) for several pages. Layout for those pages are the same but sidebar content on each page will be different. Rather than having to create separate page templates simply to be able to call different sidebars, can I write a function that would specify "if this page, call this sidebar"?
At the codex, on this page http://codex.wordpress.org/Function_Reference/get_sidebar it has a section: Multi Sidebars. I tried adapting that code but it doesn't seem to work. It seems to be what I want, but in the examples it's using stock pages and my pages have custom names -- don't know if that's problem.
Also, I'm calling the sidebars after the loop - don't know if that's the problem?
My current (not working) code is:
<?php if ( is_customer() ) : get_sidebar('customer'); elseif ( is_vendors() ) : get_sidebar('vendors'); elseif ( is_services() ) : get_sidebar('services'); else : get_sidebar(); endif; ?>
I have sidebars called sidebar-customer, sidebar-vendors, sidebar-services, and pages called customer, vendors, services, etc. I have the code in the page.php template in the place where, if I had one sidebar I would simply have:
<?php get_sidebar(); ?>
Help greatly appreciated!
@m0r7if3r I think you're coming the closest to what I'm trying to do but not exactly.
The site is not a blog, first of all. It consists of several "static" pages. I have a homepage template just for the home; the page.php (default) template for most of the internal pages, a 404 template and a small one-column template for little pages.
The page.php template has 2 columns - a wider area for the main content, and a narrow column to the right. I want to use the right columns as "sidebars" but the content of the sidebars will be different for each page.
So, say I have pages like: Customer Service, About Us, Services, and Contact. I want to use the page.php template for all of them, but the sidebar content will be different for each. In the past I would register 4 (or 5 or however many I needed) sidebars, and then create separate templates, the only difference in the templates being that they call different sidebars. I just wondered if there was a neater way of doing this.
My idea was that I would have a sidebar that went with each page and basically would do an if/then in the page.php where I would normally call the sidebar: if this is the customer service page, call the customer service sidebar; if this is the about page, call the about sidebar.
But I don't know if that's possible and if it is, precisely what the exact steps and wording would be. I don't know if I'd use the page names, ID's, etc. I assume I would need the created pages and the registered sidebars but after that I'm not sure what to do. I thought it was possible because of the "Multi Sidebars" section on the "get sidebar" functions page in the codex but I'm probably misunderstanding it. I have the link in my first entry; scroll down on the page and see Multi Sidebars.