The following warnings occurred:
Warning [2] Undefined array key "threadviews_countguests" - Line: 745 - File: showthread.php PHP 8.1.31 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/showthread.php 745 errorHandler->error_callback
Warning [2] Undefined array key "allowautourl" - Line: 584 - File: inc/class_parser.php PHP 8.1.31 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/class_parser.php 584 errorHandler->error_callback
/inc/class_parser.php 228 postParser->parse_mycode
/inc/functions_post.php 830 postParser->parse_message
/showthread.php 916 build_postbit
Warning [2] Undefined property: MyLanguage::$thread_modes - Line: 46 - File: showthread.php(1650) : eval()'d code PHP 8.1.31 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/showthread.php(1650) : eval()'d code 46 errorHandler->error_callback
/showthread.php 1650 eval




Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Different Sidebars for each page
#8
(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-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
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!  Big Grin
Reply


Messages In This Thread
Different Sidebars for each page - by sher4 - 2014-05-02, 17:56:15
RE: Different Sidebars for each page - by Timbow - 2014-05-02, 20:16:30
RE: Different Sidebars for each page - by sher4 - 2014-05-02, 20:49:03
RE: Different Sidebars for each page - by Timbow - 2014-05-02, 21:30:23
RE: Different Sidebars for each page - by jezburns - 2017-02-07, 03:30:04
RE: Different Sidebars for each page - by Lars - 2014-05-03, 09:22:00



Users browsing this thread: 2 Guest(s)