Use navigation path from menu for permalink

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.

Read More

How can this be done?

Related posts

Leave a Reply

3 comments

  1. Yes, I could set the menu structure, but I don’t know if the user would make this, when he creates a new page. The difference is here because I needed the hierarchy for some special adaptions I made (read the content from certain sub pages and so on …). Normally, the menu should define the structure of the permalink. That’s the reason why I asked for it. And the menu hierarchy is already available. So one would have to define the hierarchy two times. Perhaps I don’t understand a certain concept.

    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.

  2. THE PERMALINKS

    The permalinks in WordPress are generated by WP_Rewrite class in wp-includes/rewrite.php. It translates the URL being entered into the browser into query variables which are then used by WP_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, where custom_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:

    1. You have to create custom structure for each part of your page which
      are categories, tags, port_formats, taxonomies, posts etc.
    2. You have to create rewrite rule for them as well.
    3. You have to make sure that they don’t conflict each other.
  3. 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:

    <ul>
    <?php wp_list_pages('&title_li=<h2>Pages</h2>' ); ?>
    </ul>
    

    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