This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
components-depending-on-the_page [2013/07/30 08:12] Timbow [Excluding components] |
components-depending-on-the_page [2017/02/28 00:56] (current) Timbow [Several Pages Each with Different Components] |
||
---|---|---|---|
Line 5: | Line 5: | ||
Don't forget to replace **PAGE** with your **page's slug** and **COMPNAME** with the **component's name**. | Don't forget to replace **PAGE** with your **page's slug** and **COMPNAME** with the **component's name**. | ||
+ | |||
+ | =====Several Pages Each with Different Components===== | ||
+ | Say you have three pages with the slugs //index//, //about//, //contact// and sidebars as components named //peter//, //paul// and //mary// you would edit your template to replace <code><?php get_component(sidebar); ?></code> with | ||
+ | <code> | ||
+ | <?php if (return_page_slug()=='index') {get_component('peter');} | ||
+ | elseif (return_page_slug()=='about') {get_component('paul');} | ||
+ | else {get_component('mary');} ?> </code> | ||
+ | which in English reads | ||
+ | |||
+ | >**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//. | ||
+ | |||
+ | |||
===== Components Depending On The Parent Page ===== | ===== Components Depending On The Parent Page ===== | ||
Line 20: | Line 32: | ||
The Components might contain a header image, sidebar content, tagline text, anything. If you only want one page to be different it might be simplest to just make a duplicate page template, but if you want them different on each of several pages here is how. | The Components might contain a header image, sidebar content, tagline text, anything. If you only want one page to be different it might be simplest to just make a duplicate page template, but if you want them different on each of several pages here is how. | ||
- | The following text needs to be in a functions.php file in your theme: | + | The following text needs to be in a functions.php file in your theme folder: |
- | <file><?php | + | <file php><?php |
if (!function_exists('component_exists')) { | if (!function_exists('component_exists')) { | ||
function component_exists($id) { | function component_exists($id) { | ||
Line 48: | Line 60: | ||
Make a component which will be the default component and call it say //default//. Make components for specific pages and name them to include the page slug of the page into which they are to be inserted, so name them say //content-about// and //content-contact//. Then call the component in your page template as follows: | Make a component which will be the default component and call it say //default//. Make components for specific pages and name them to include the page slug of the page into which they are to be inserted, so name them say //content-about// and //content-contact//. Then call the component in your page template as follows: | ||
- | <code> | + | <code php> |
<?php if (component_exists('content-'.get_page_slug(false))) | <?php if (component_exists('content-'.get_page_slug(false))) | ||
{get_component('content-'.get_page_slug(false));} | {get_component('content-'.get_page_slug(false));} | ||
Line 54: | Line 66: | ||
======Links====== | ======Links====== | ||
+ | Back to the GetSimple Wiki [[:start|Contents Page]] | ||
===How to Have Different sidebars=== | ===How to Have Different sidebars=== | ||
[[http://mvlcek.bplaced.net/how-to/sidebars/]] | [[http://mvlcek.bplaced.net/how-to/sidebars/]] |