| re: XML powered all-knowing menu
Bizt wrote:[color=blue]
> Hi,
>
> I would like to create a menu where the menu options were taken from
> an XML file. The reason is that I would be able to update the xml[/color]
file[color=blue]
> (by simply adding new child nodes) after I uploaded new web pages.
> Each page would run the same PHP script to create the menu. As the[/color]
xml[color=blue]
> file would supply every page, this would mean less time taken up when
> adding new pages. Below is an example of the xml file content:
>
>
> <?xml...
> <menu>
> <option title="Home" href="home.php">
> <option title="Gallery" href="gallery.php">
> <option title="Paintings" href="paintings.php">
> <option title="Drawings" href="drawings.php">
> <option title="Links" href="links.php">
> <option title="Contact" href="contact.php">
> </menu>
>
>
> When the menu is displayed in the browser it would look like this:
>
>
> Home
> Gallery
> Links
> Contact
>
>
> Each would contain html (<a href...) to allow it to link to another
> page but, for example, if the user clicked the Gallery link the next
> page would look like this:
>
>
> Home
> Gallery
> Paintings
> Drawings
> Links
> Contact
>
>
> This would, however, require that the script knows where the user[/color]
was.[color=blue]
> I figured using a GET variable somehow so that the script could open
> the correct menus'.
>
> I did manage to create a script that could do what I am asking here.
> It also allowed me to add new menu options (which is why I opted to
> create this in the first place). The problem was I had to predefine
> how many levels the xml tree structure would have. I want to be able
> to create a script that can allow any amount of levels to be used and
> allow the next page to be able to open the correct menu. For example,
> my multi-level xml file may look something like this:
>
>
> <?xml...
> <menu>
> <option title="Home" href="home.php">
> <option title="News" href="news.php">
> <option title="Recent News" href="recentnews.php">
> <option title="Archive" href="archive.php">
> <option title="About me" href="news.php">
> <option title="Disclaimer" href="news.php">
> <option title="Gallery" href="gallery.php">
> <option title="Paintings" href="paintings.php">
> <option title="Drawings" href="drawings.php">
> <option title="Links" href="links.php">
> <option title="Contact" href="contact.php">
> </menu>
>
>
> As the new menu shows, Gallery (as before) only has the two levels
> (i.e. Gallery>Paintings or Gallery>Drawings) whereas Home has three
> levels within (i.e. Home>News>Recent News). So when the user is[/color]
within[color=blue]
> the Recent News page, the new menu will look like this:
>
>
> Home
> News
> Recent News
> Archive
> About me
> Disclaimer
> Gallery
> Links
> Contact
>
>
> I figured this would require that the script is passed a variable,
> contained in the menu link (GET), from the previous page. The[/color]
variable[color=blue]
> would contain informtion for the same script running on the next page
> to open the correct menu from the xml file. This is that part that i
> dont know how to do.
>
> How could I pass information from one page to the next for the script
> (used by all pages) to open the correct menu? If there are any[/color]
scripts[color=blue]
> that are availble online that could do something similar, please
> direct me? If anybody has anything that could point me in the right
> direction please comment. Thanks
>
> Burnsy[/color]
you don't need passed vars. i see two ways:
1. your xml contains the href and your file has an uri. compare the two
to find out which option the user clicked on(i.e. which file is open
now). i found that unreliable if your content stretches over a couple
of folders.
2. each file contains a value determining it's position in the nav.
that' what i use.
now the structure
1. if you wanna stick with xml:
use DOM XML funtions to find parent/child nodes to find out which
submenus to display. lot of bother for just a nav in my opinion.
2. use an multidimensional array instead of xml
style of
$nav['menu_name']['void'] = "href"; //this would be a main menu item
$nav['menu_name']['submenu1_name'] = "href"; // and it's submenu items
$nav['menu_name']['submenu2_name'] = "href";
each page is contains simply contains info for it's matching array
element. this way you can assign a couple of files to one menu item,
too (i needed that, because there's files on my page which are not
accessible through the nav, but only among each other)
micha |