I now switched to permalinks and defined my own structure
/%postname%
. If I click on a menu item it takes the path from the parent page (hierarchy defined directly when editing a page).
What I want is for the permalink to use the structure of the menu.
How can this be done?
The “menu” doesn’t define anything in any web application. At least not if the architecture isn’t bogus and assumes that everyone actually got a menu. There’re other navigation ideas as well.
To get data from the siblings of a page, you can use
get_page_children()
– detailed use case in Codex. That function will work for hierarchical post types as well.THE PERMALINKS
The permalinks in WordPress are generated by
WP_Rewrite
class inwp-includes/rewrite.php
. It translates the URL being entered into the browser into query variables which are then used byWP_Query
to determine which content will be loaded.There are rewrite rules which define the structure of permalinks.
Categories are structured by default as
website/category/category_name
Pages are structured as
website/pagename
For posts, it is
website/custom_structure
, wherecustom_structure
is what you define on the Settings > Permalink on admin page.Pages, by default, reflect their parents. So third level page will have:
website/Level1/Level2/Level3
THE NAVIGATION MENU
The navigation menu doesn’t reflect the permalink, it depends on how user will build the structure of the menu.
So, if you need the menu to follow the page structures, create a menu based on them. Having the permalink structure follow your menu takes more effort than you could imagine.
Having custom permalinks requires these actions:
are categories, tags, port_formats, taxonomies, posts etc.
i think you could be using the wp_nav_menu function to display a menu that is defined inside the appearance > menu section.
To do what you want, you’d have to use wp_list_pages to list the pages in the order and hierarchy that they are in on the dashboard:
This will output a menu in an un ordered list that replicates the structure of your Pages, including their child pages etc, indented via an unordered listm complete with the correct permalinks