I know there are a lot of new WordPress developers out there trying to figure out the core framework. From time to time, we’ll post a few tips here and there so that you can gain some insight into what we do. Here’s a trick that you may have not come across yet. If you want to load the navigation dynamically in WordPress (meaning ever additional pages added in the backend will also show up on the frontend menu) , here’s the code that can make it happen.
<?php wp_list_pages(); ?>
This code above will call in the navigation dynamically as is. However if you do decide that you only want to show the parent navigation, you can simply add a parameter to the function.
<?php wp_list_pages(‘depth=1’); ?>
What we are instructing WordPress to do is to create a list of pages that we have in the backend, then only show the top level navigation. If you change that 1 to a 2, WordPress will output the top level and second level navigation, ignoring anything outside of that. If you want to see the full definition of the function, you can check it out here:
http://codex.wordpress.org/Template_Tags/wp_list_pages