Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
1  
What do you mean by 'takes the path from the parent page' - do you mean that the permalink of pages reflects its hierarchy: e.g. if page2A was a child of page1, it has permalink www.example.com/page1/page2a? –  Stephen Harris May 1 '12 at 11:38
    
@StephenHarris: Yes, I mean that! This is the current situation and I want to change this behavior. The hierarchy of the menu should be chosen not the one of your example. –  testing May 1 '12 at 12:14
3  
Why can't you set the parents according to the menu structure? (Or more usually, have the menu reflect the parent-child relationship). Why is there a difference between the page and menu relationships? –  Stephen Harris May 1 '12 at 13:38
    
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. Thats 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 ... –  testing May 1 '12 at 14:09
1  
WP has a lot of complexities to account for in its URLs. I've been thinking about this exact same thing but there are many edge cases like feeds, single posts, comment pages, custom rewrite endpoints etc... Total nightmare –  sanchothefat Jun 13 '12 at 16:46

3 Answers 3

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.

share|improve this answer

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

share|improve this answer
    
Please explain how that could solve the problem. Add a code example. Right now it doesn’t even look like an answer. –  toscho Jun 25 '13 at 7:37
    
the wp_nav_menu outputs a menu so it visually looks like there is a hierarchy, but the pages in the menu might all exist at the same level (i.e. flat). If the pages are in a tree like structure (ie parent > child, etc) the wp_list_pages will output html that adheres to the relationship of the pages, including the permalinks: <ul> <?php wp_list_pages('&title_li=<h2>Pages</h2>' ); ?> </ul> –  Terry Kernan Jun 25 '13 at 10:00
    
Please update your answer, do not hide essential information in a comment. –  toscho Jun 25 '13 at 10:03
    
answer updated :) –  Terry Kernan Jun 25 '13 at 10:15

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.
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.