Posts: 2
Threads: 1
Joined: May 2014
I am a newbie and whilst I've managed to set up 3 pages etc I do not understand how to have separate sidebars for each page. I do not really understand how a page connects to the sidebar.
I have read the post:
http://get-simple.info/forums/showthread...t=sidebars
but I have absolutely no idea where to put the code:
<?php get_component((string) return_page_slug()); ?>
Any help would be very much appreciated thanks.
Posts: 52
Threads: 2
Joined: May 2013
You want to put that code in the '
template.php' file of your theme (
/themes/Theme-Folder/template.php) right in the place where the component with the proper sidebar needs to be.
This might be a good read.
Posts: 1,127
Threads: 136
Joined: Feb 2012
In your theme the file
template.php will have the tag in it
PHP Code:
<?php get_component('sidebar'); ?>
which inserts the contents of the component
sidebar into every page which uses that template.
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-d...n-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
PHP Code:
<?php if (return_page_slug()=='index') {get_component('peter');}
elseif (return_page_slug()=='about') {get_component('paul');}
else {get_component('mary');} ?>
which in English reads
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.
Posts: 2
Threads: 1
Joined: May 2014
Thank you so much for your detailed instructions Timbow and your help Everyone - I finally understand not only how to have separate sidebars but also more about the structure of pages and components etc. I have knowledge of html & CSS but php is very challenging for me.
Apart from my own challenges I think GetSimple is the best CMS I've found so far and with Forum help such that I've just received - it can't get much better than this.
My thanks again....!
Posts: 1,127
Threads: 136
Joined: Feb 2012
(2014-05-02, 20:49:03)sher4 Wrote: Thank you so much for your detailed instructions Timbow ...
My thanks again....!
Actually I wrote the php wrong, I am correcting it now.
Done. I had left out the {}s .
I should keep my mouth shut really because I am still only learning this php stuff.
Posts: 1,247
Threads: 82
Joined: Feb 2011
If I'm not mistaken, this can be easier maintained by using the
I18N Custom Fields plugin.
Posts: 116
Threads: 8
Joined: Oct 2011
2014-05-03, 09:22:00
(This post was last modified: 2014-05-03, 09:23:56 by Lars.)
In nearly any Webpage I use diffrent sidebars. Anything is dependend from the slug:
- Read the Slugname, extend it with e.g. "-sidebar"
- check if "slugname-sidebar.xml" exists
- If not, display a default one or nothing
- otherwise display the "slugname-sidebar.xml"
With the same technique you can set up different CSS files for any page if you want.
Of cource the custom fields plugin is more comfortable, but the slug-solution works out of the box.
Posts: 3
Threads: 0
Joined: Apr 2015
(2014-05-02, 20:16:30)Timbow Wrote: In your theme the file template.php will have the tag in it
PHP Code:
<?php get_component('sidebar'); ?>
which inserts the contents of the component sidebar into every page which uses that template.
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-d...n-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
PHP Code:
<?php if (return_page_slug()=='index') {get_component('peter');}
elseif (return_page_slug()=='about') {get_component('paul');}
else {get_component('mary');} ?>
which in English reads
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!