I have a question that I haven’t been able to find the answer/script to. I’m just learning to use PHP. I’m using Perch as a CMS and has been going great so far.
I’ve run into a snag when it comes to adding new pages. Something that I want PHP to do is be able to create a dynamic navigation menu for only that directory.
For example, I have three pages in my ‘about’ directory.
root
/about
/index.php
- page2.php
- page3.php
I want to be able to output a side navigation menu based off only that directory.
Home - Page2 - Page3
And when the client/user creates a new page, it’ll automatically add it to the list. So…
root /about /index.php - page2.php - page3.php - newPage.php
…creates…
Home - Page2 - Page3 - New Page
Can anyone point me into a direction of a script or help me get started?
Thanks!
There are quite a few php functions to iterate through directories. I think the cleanest is using PHP SPL (Standard PHP Library)’s Directory Iterator.
http://www.php.net/manual/en/class.directoryiterator.php
The advantage is you have a lot of class functions available to you.
If you need more than the filename you can use:
getPathname()getPath()getBasename()isDir()And so on… see the docs for all the possibilities.