Jump to content


Photo

dynamic site structure and menu


  • Please log in to reply
5 replies to this topic

#1 defborn

defborn
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 15 May 2006 - 02:04 PM

Hello

I have to make this new website, without CMS or database, it's a corporate website. I want it to be a little bit dynamic, so I thought about throwing the website structure into an array.
The problem is now where to go from here?

Here is my array (the items are fictional, but represent a possible structure:
$menu = array(
"Home" => "home.php",
"products" 
        => array
        (
        "root" => "products.php",
        "Hardware" 
            => array
            (
            "root"                    =>    "products-hardware.php",
            "screens"     =>     "products-hardware-screens.php", 
            "desktops"                    =>     "products-hardware-desktops.php",
            "workstations"             =>     "products-hardware-workstations.php", 
            "Policy & practice" =>     "services-consulting-policy-practice.php"
            ), 
        "Software"
            => array
            (
            "root"                    =>    "products-software.php",
            "office"                 =>     "products-software-office.php", 
            "management"     =>     "products-software-management.php"
            ),
        "Whatever"         => "products-whatever.php"
        ),
"services" 
        => array
        (
        "support" 
            => array
            (
            "root"                    =>    "services-support.php",
            "general support"     =>     "services-support-general-support.php", 
            "no support"                    =>     "services-support-no-support.php"
            ), 
        "catering"
            => array
            (
            "root"                    =>    "services-catering.php",
            "Sandwiches"                 =>     "services-catering-sandwiches.php", 
            "Weddings"     =>     "services-catering-weddings.php"
            ),
        "Mechanic"         => "services-mechanic.php"
        )
);

What I would like to do is build my main menu of the root items (home | products | services), but that I can do. Further when you click products, you should go to products.php off course, and there get a submenu of hardware, software and whatever. When clicking one of those .. well the idea is obvious.

I thougth about getting a url (since I work with the one script serves all method) like this:
index.php?page=products&sub1=hardware&sub2=screens

But I don't know if that is good, and even how I could get the values out of that querystring (I tried regular expressions, but all I get is the keys, not the values).

Maybe my method is complete wrong, and I should use another approach. But what my goal was with this, is that when a new category comes, no matter what level it is in, all that has to be done for the developers using it afterwards is adding the physical page with the same naming convention, and adding an item to the array.

Tnx for all the help.



#2 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 15 May 2006 - 02:50 PM

[!--quoteo(post=373992:date=May 15 2006, 09:04 AM:name=defborn)--][div class=\'quotetop\']QUOTE(defborn @ May 15 2006, 09:04 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I thougth about getting a url (since I work with the one script serves all method) like this:
index.php?page=products&sub1=hardware&sub2=screens

But I don't know if that is good, and even how I could get the values out of that querystring (I tried regular expressions, but all I get is the keys, not the values).
[/quote]

that's just the get method. you can access any variables in there from inside the $_GET array. so, $_GET['page'] will provide the value of "page" in the address.

As for the arrays, I'm not quite sure where you're going with that.

#3 macdumbpling

macdumbpling
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 15 May 2006 - 03:44 PM

use foreach() loops to build your menus. You can give the main sections a class characteristic and the subsections different class characteristics (for example, you could write it so the main sections are visible and the subsections are hidden and create a drop-down menu using javascript. or you could just set it up as a list style on the left side of the screen).

you have to set up each part of the array the exact same for this script, so:
"Home" => array(
"root" => "home.php"
)
"Products" => array(
"root" => "products.php"
)

foreach($menu as $mainSection => $subSections){
  foreach($subSections as $subSection => $values){
    if($subSection == "root"){ // it's the main section's page value
      $strMenu .= "<a href=\"$values\">$mainSection</a>";
    }else{ // it's another subsection
      if(is_array($values)){
        foreach($values as $subSubSection => $sssValue){
          $strMenu .= "<a href=\"$sssValue\">$subSection</a>";
        }
      }
    }
  }
}

Okay...I'm done with that....I was doing this on the fly so it might not be entirely correct, but give it a shot and you can change the variable names (I'm not good at naming variables).

I really HTH

#4 defborn

defborn
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 15 May 2006 - 03:48 PM

Sometimes I'm really amazed by the time and effort people put in these answers, but it's great!! Thanks a million! I'll try it out.

[!--quoteo(post=374033:date=May 15 2006, 05:44 PM:name=macdumbpling)--][div class=\'quotetop\']QUOTE(macdumbpling @ May 15 2006, 05:44 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
use foreach() loops to build your menus. You can give the main sections a class characteristic and the subsections different class characteristics (for example, you could write it so the main sections are visible and the subsections are hidden and create a drop-down menu using javascript. or you could just set it up as a list style on the left side of the screen).

you have to set up each part of the array the exact same for this script, so:
"Home" => array(
"root" => "home.php"
)
"Products" => array(
"root" => "products.php"
)

foreach($menu as $mainSection => $subSections){
  foreach($subSections as $subSection => $values){
    if($subSection == "root"){ // it's the main section's page value
      $strMenu .= "<a href=\"$values\">$mainSection</a>";
    }else{ // it's another subsection
      if(is_array($values)){
        foreach($values as $subSubSection => $sssValue){
          $strMenu .= "<a href=\"$sssValue\">$subSection</a>";
        }
      }
    }
  }
}

Okay...I'm done with that....I was doing this on the fly so it might not be entirely correct, but give it a shot and you can change the variable names (I'm not good at naming variables).

I really HTH
[/quote]


#5 defborn

defborn
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 16 May 2006 - 09:38 AM

[!--quoteo(post=374012:date=May 15 2006, 04:50 PM:name=michaellunsford)--][div class=\'quotetop\']QUOTE(michaellunsford @ May 15 2006, 04:50 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
As for the arrays, I'm not quite sure where you're going with that.
[/quote]

Well, I don't know if it's the best way to do it, but I want my site structure to be editable in one file, say they want to add 2 categories, then they will know to add the 2 physical pages, and update the arrays with the new values.

I don't see another way right now... But I am open for improvements :)


#6 haydndup

haydndup
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts
  • LocationJohannesburg, South Africa

Posted 16 May 2006 - 09:52 AM

Have you considered using the include ()?

Put you menu arrays, or whatever you are doing to set up the navigation structure in a file. eg menu.php
then include menu.php on all pages.

<?php

include 'menu.php';

?>

I use something similar on my websites, i have a top.php, left.php, and bottom.php and the site layout is distributed between the three files, allowing me to quickly and easily change layout etc
[!--coloro:#660000--][span style="color:#660000"][!--/coloro--]The Gene Pool Could Use A Little Chlorine[!--colorc--][/span][!--/colorc--]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users