Welcome, Guest. Please login or register.
Did you miss your activation email?
February 04, 2012, 06:42:17 AM

Login with username, password and session length
Search:     Advanced search
Wollen Sie dem WebsiteBaker Team beitreten?
Nähere Informationen finden Sie unter hier und auf unserer neuen Webseite.
149021 Posts in 21045 Topics by 7522 Members
Latest Member: ThomasFrank
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: Creating Menus with Child Sections  (Read 1727 times)
designrunway

Offline Offline

Posts: 36


« on: August 06, 2005, 10:34:40 PM »

I'm not sure if this has been attempted before, or if it's possible.

I am creating the following site structure

Parent Root
- Child 1
-- Child 1 Sub Pages
- Child 2
-- Child 2 Sub Pages

When a user clicks on Child 1, I would like the Child 1 page to display a menu with only Child 1 Sub Pages. I would like to Child 2 to operate similarly.

I found this thread on the forum and didn't quite understand if his/her needs were similar to mine.
http://www.websitebaker.org/2/forum/index.php?topic=711.0

Thanks in advance.
Logged
designrunway

Offline Offline

Posts: 36


« Reply #1 on: August 09, 2005, 04:01:05 AM »

Ok

I think I got it. I concede that it might not be the best method, but it worked for me. If any administrators (Ryan?) of this site see this as useful, please feel free to use the below as documentation.  I errored on the side of being more thorough. I'll try to explain all of the steps in a manner that even new users should be able to understand.


1). Change Advanced Settings to use Multiple Menus [Settings > Advanced Options] in the Administration Menu
2). Modify info.php [in the template directory] for each template you plan to utilize these submenus. If you plan to create two submenus for each template, you need to specify two ADDITIONAL menus by inserting the following code in info.php.
$menu[2]='Menu 2';
$menu[3]='Menu 3';
..etc
3). Modify the index.php in the root folder using the following code.
[In version 2.5.2, lines 396 to 514]
- Copy the entire function: // Function to generate menu
- Change the variables names found below throughout the function. I did a find, but manually replaced so that I could inspect the code. [Seems silly to mention, but a find and replace if you don't copy and paste into a new file, will change the original Function to generate menu.]
- Be careful not to modify other functions or global variables.
===
[I found it useful to paste the entire function in another page to modify temporarily so as not to affect your site in case of a blunder. Then I copied and pasted back into my index.php file. Making a copy of index.php before this cut and paste operation isn't a bad idea either so as to minimize risk]. Basically I changed the following function names, appending a '2' to each one. For each custom menu you create, you will need to increment this number.
===

// Changed variables
page_menu
set parent = 7 [change to the pageID of the parent]
set menu_number = [change to include items of parent menus. ]
item_template
menu_header
menu_footer
default_class
current_class
query_menu
page
vars
class
link
values

[Match page_menu# with MENU_NUMBER]

function page_menu2($parent = 7, $menu_number = 1, $item_template2 = '<li[class]>[a][menu_title][/a]</li>', $menu_header2 = '<ul>', $menu_footer2 = '</ul>', $default_class2 = ' class="menu_default"', $current_class2 = ' class="menu_current"', $recurse = LEVEL) {
   global $database, $admin, $page_id, $page_trail, $default_link, $extra_sql, $extra_where_sql;
   // Check if we should add menu number check to query
   if($parent == 7) {
       $menu_number2 = "menu = '$menu_number2'";
   } else {
      $menu_number = '1';
   }
   // Query pages
   $query_menu2 = $database->query("SELECT page_id,menu_title,page_title,link,target,level,visibility$extra_sql FROM ".TABLE_PREFIX."pages WHERE parent = '$parent' AND $menu_number AND $extra_where_sql ORDER BY position ASC");
   // Check if there are any pages to show
   if($query_menu2->numRows() > 0) {
      // Print menu header
      echo $menu_header2;
      // Loop through pages
      while($page2 = $query_menu2->fetchRow()) {
         // Create vars
         $vars2 = array('[class]', '[a]', '[/a]', '[menu_title]', '[page_title]');
         // Work-out class
         if($page2['page_id'] == PAGE_ID) {
            $class2 = $current_class2;
         } else {
            $class2 = $default_class2;
         }
         // Check if link is same as first page link, and if so change to WB URL
         if($page2['link'] == $default_link AND !INTRO_PAGE) {
            $link2 = WB_URL;
         } else {
            $link2 = page_link($page2['link']);
         }
         // Create values
         $values2 = array($class2, '<a href="'.$link2.'" target="'.$page2['target'].'">', '</a>', stripslashes($page2['menu_title']), stripslashes($page2['page_title']));
         // Replace vars with value and print
         echo str_replace($vars2, $values2, $item_template2);
         // Generate sub-menu
         if(isset($page_trail[$page2['page_id']])) {
            page_menu2($page2['page_id'], $menu_number2, $item_template2, $menu_header2, $menu_footer2, $default_class2, $current_class2, $recurse-1);
         }
      }
      // Print menu footer
      echo $menu_footer2;
   }
}

4). Modify Menu in the respective Template.
<?php page_menu(PARENT_PAGE_ID_NUMB ER, MENU_NUMBER); ?>
[Users that define additional

5). Save and Ready to Go.


I hope this helps.
            
Logged
Stefan
Guest
« Reply #2 on: August 09, 2005, 08:15:22 AM »

Have you looked at my "improved menu"? You can do a lot more with it than with the original menu and you don't need the multiple menu tweak.
Get it here, copy it into your template's index.php file and change the line
Code:
<?php page_menu()?>
to
Code:
<?php menu(1,LEVEL?>
You can have more than one menu displayed, for example one top menu (for the navigation of root pages) and a left side menu for the sub pages.
Logged
designrunway

Offline Offline

Posts: 36


« Reply #3 on: August 09, 2005, 07:00:04 PM »

I'll play around with that idea too.

The reason for the menu tweak is that the org that needs the site wants to combine two existing sites into a "family site" that contains both child sites, and some information at the parent level.

However, each child will be large sites: over 100 pages each, with approx 6-10 levels. The organization doesn't want long complicated menus (ie. basically the org doesn't want the nav menu to turn into a site map).

I concede that this implementation is not the most usable solution, however, i am trying to balance that with the demands of the site to be visually pleasing.

I have also placed a static top nav menu that should help users find their way to the main parent and the main child sites.

Thanks for the suggestion though. I'll see if I can work the breadcrumb and advanced menus into this implementation.
Logged
v2006

Offline Offline

Posts: 72


« Reply #4 on: February 13, 2006, 12:25:08 AM »

Quote
copy it into your template's index.php file and change the line
Code:
<?php page_menu()?>to

Code:
<?php menu(1,LEVEL) ?>You can have more than one menu displayed, for example one top menu (for the navigation of root pages) and a left side menu for the sub pages.

Where exactly do you add the improved menu code in the index.php file?
Logged
ruebenwurzel
WebsiteBaker Org e.V.

Offline Offline

Posts: 7631



WWW
« Reply #5 on: February 13, 2006, 06:54:30 AM »

Hello,

if you are using WB 2.6.x the improved menu is implemented in the code of WB. You don't need to copy any code to your template files. To get it diesplayed use

Code:
<?php show_menu()?>

The parameters you can give are the same as described in improved menu.

Matthias
Logged
dellington

Offline Offline

Posts: 86


« Reply #6 on: April 12, 2006, 05:00:33 PM »

So glad I found this page -- I needed to do exactly this task. Thanks!
Logged
Pages: [1]   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!