morbid_leathal92
Member
- Messages
- 64
- Reaction score
- 0
- Points
- 6
How to program a dynamic nested navigation menu in Php?
<nav id="top_navigation">
<ul>
<li><a href="/" title="Return to Home Page">Home</a></li>
<li><a href="/about" title="Go to About Us">About</a></li>
<!-- dynamic stuff starts here -->
<li><a href="/some_main_topic">Some Main Topic</a>
<ul class="subcategory">
<li><a href="/yadayada">A subtopic</a></li>
<li><a href="/chachacha">Another subtopic</a></li>
<li><a href="/yabadabadoo">A third subtopic</a></li>
</ul>
</li>
<li><a href="/another_main_topic">Another Main Topic</a>
<ul class="subcategory">
<li><a href="/booyah">A different subtopic</a></li>
<li><a href="/okeydokey">Yet another subtopic</a></li>
<li><a href="/zippidydoodah">Enough subtopics Already</a></li>
</ul>
</li>
<!-- dynamic stuff ends here -->
<li><a href="/contact" title="Leave a message or learn how else to contact us">Contact Us</a></li>
</ul>
</nav>
As for the question being too vauge, it is onlo so if you are reading past the specifics.
I was looking for the .css used in the example.
One who learns from their mistakes is smart.
The one who learns from other's mistakes is smarter.
I hate to be "that guy", but I have to be: your question is really too broad to answer as it stands. To properly answer the question, we'd need to know something about your site's structure, and how that structure is stored.
In the most general sense, you want to create an HTML structure composed of unordered lists packaged in a <div> (HTML 4.01, XHTML) or <nav> (HTML5) element to identify it as the navigation area:
HTML:<nav id="top_navigation"> <ul> <li><a href="/" title="Return to Home Page">Home</a></li> <li><a href="/about" title="Go to About Us">About</a></li> <!-- dynamic stuff starts here --> <li><a href="/some_main_topic">Some Main Topic</a> <ul class="subcategory"> <li><a href="/yadayada">A subtopic</a></li> <li><a href="/chachacha">Another subtopic</a></li> <li><a href="/yabadabadoo">A third subtopic</a></li> </ul> </li> <li><a href="/another_main_topic">Another Main Topic</a> <ul class="subcategory"> <li><a href="/booyah">A different subtopic</a></li> <li><a href="/okeydokey">Yet another subtopic</a></li> <li><a href="/zippidydoodah">Enough subtopics Already</a></li> </ul> </li> <!-- dynamic stuff ends here --> <li><a href="/contact" title="Leave a message or learn how else to contact us">Contact Us</a></li> </ul> </nav>
Such a list is easily styled, using CSS, to look and act like one would expect a navigation menu to look and act. Several of the items on the navigation menu will be static (that is, they're unlikely to change), so you can hard-code them into the page. Beyond that, it's a matter of creating the elements between the comments, and how you do that depends on how the data is organised on your site and on how deep you want the navigation to go.