Multilevel Navigation from files and folders

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ApheX87
Forum Newbie
Posts: 1
Joined: Wed Nov 22, 2017 7:33 am

Multilevel Navigation from files and folders

Post by ApheX87 »

Hello Community,

ive just signed up and this is my first post in here, so dont bare with me if im in the wrong subforum please.
I came here because i stuck in a problem that confuses me so much that im just unable to solve it on my own...

i need to create an self-building navigation from directorys, my current folder-structure looks like this:

[Main Folder] Modules:
- [Folder] Tools
- - [Subfolder] Tool One
- - - index.php
- - [Subfolder] Tool Two
- - - index.php
- [Folder] Projects
- - [Subfolder] Project One
- - - [Sub(Sub)folder] Project Tool One
- - - - index.php
- - - [Sub(Sub)folder] Project Tool Two
- - - - index.php
- - - [Sub(Sub)folder] Project Tool Three
- - - - index.php
- - [Subfolder] Project Two
- - - [Sub(Sub)folder] Project Tool
- - - - index.php

it should be possible to randomly add directorys with files anywhere inside the Modules folder and the script checks on his own whats new, where it belongs, how its named and add it to the navigation.

like:

Code: Select all

<ul>
  <li>tools
    <ul>
      <li><a href="/index.from.path">Tool One (basicly the folders name on all examples here)</a></li>
      <li><a href="/index.from.path">Tool Two</a></li>
    </ul>
  </li>
  <li>Projects
    <ul>
      <li>Project One
        <ul>
          <li><a href="/index.from.path">Project Tool One</a></li>
          <li><a href="/index.from.path">Project Tool Two</a></li>
          <li><a href="/index.from.path">Project Tool Three</a></li>
        </ul>
      </li>
      <li>Project Two
        <ul>
          <li><a href="/index.from.path">Project Tool</a></li>
        </ul>
      </li>
    </ul>
  </li>
</ul>
is something even possible or cant i just dont see the forrest between all those trees?

i hope some of you are able to help me here.

best thanks and greetings from germany

- sorry for my bad english :S
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Multilevel Navigation from files and folders

Post by requinix »

Are you able to make a function that creates one simple <ul> for a given directory? Like

Code: Select all

function print_navigation($directory, $urlroot = "") {
	echo "<ul>";
	/* print items in $directory */
	echo "</ul>";
}
$directory is the path to use and $urlroot is the URL prefix for the directory - like Tool One's index.php would be $urlroot = "/Modules/Tools/Tool One" (or something similar).

If that function is written then it's easy to make it recursive: it calls itself to print subdirectories as it comes across them.
Post Reply