2017-02-07, 03:30:04
(2014-05-02, 20:16:30)Timbow Wrote: In your theme the file template.php will have the tag in it
which inserts the contents of the component sidebar into every page which uses that template.PHP Code:<?php get_component('sidebar'); ?>
An easy way to get a different sidebar on a new page is to copy and rename template.php and edit the new template to insert a different component.
That's fine for a small site but not particularly good practice because now if you want to make a change elsewhere in the template you need to change every template the same. Some snippets of code for using one template and multiple components by page slug are given here:
http://get-simple.info/wiki/components-depending-on-the_page
In your case with three pages you could use the first snippet so that if you have pages with the slugs index, about, contact and components named peter, paul and mary you would replace <?php get_component(sidebar); ?> with
which in English readsPHP Code:<?php if (return_page_slug()=='index') {get_component('peter');}
elseif (return_page_slug()=='about') {get_component('paul');}
else {get_component('mary');} ?>
Quote: if the page slug is index insert the component peter, otherwise if the page slug is about insert the component paul and otherwise just insert the component mary
The more complicated and complete example on the bottom of the wiki page prevents the code from failing when a component is missing and uses the page slug in the component name so that you can add pages later with specific components without editing the template.
This is one of the most helpful comments ever - thank you!