Menus like a CMS

Here is an example structure of some content:

Parent A
-- Child A
-- Child B
Parent B
-- Child C
-- Child D

Parent A should link to the content of Child A and Parent B should link to the content of Child C. Other than that, I’m not sure if this is something that should be managed completely by “menus” in wordpress, or if it should be a Parent A page with children pages. The only problem there is that Parent A isn’t really content, just a link to Child A.

Read More

If you need a real world example, it would be something like this:

Main Navigation:

Home, Company, Products, Contact

Company
-- About Us
-- News
-- Careers

In this instance, there is not really a “Company” page, but the “Company” is really a link to “About Us”.

If “Child A” or “Child B” is selected, in the sidebar this section of the navigation should appear:

Parent A
-- Child A
-- Child B

If “Child C” or “Child D” is selected, in the sidebar this section of the navigation should appear:

Parent B
-- Child C
-- Child D

Hopefully this question makes sense. I’m trying to understand how to access the navigation items individually. I can’t even find useful methods (closest I’ve come is get_nav_menu_item_children). How should this be organized and what methods does wordpress contain that can help me achieve it?

Related posts

Leave a Reply

1 comment

  1. 3 ideas:

    1. Create the empty parent pages and use a redirect plugin to redirect all requests from these pages to the children.
    2. Inside the menu options page insert a custom link and link to the desired child page.
    3. At the top of your template – lets say page.php – test if children for this page exist and use wp_redirect() to skip this page and redirect to the children automatically.

    The last one is probably the most sophisticated one. If you are having many sites it may pay of, otherwise just stick with the custom menu. Drawback is of course, that you are forced to use this scheme on all pages.
    Creating a custom page template e.g. redirect.php and only applying the logic of 3. there would give you the option to use the children-redirect only on chosen pages.

    Edit: based on kaisers input this is how a good redirect could look like:

    function children_redirect() {
       global $wp_query;
       $child = get_children( array( 'post_parent' => $wp_query->post->ID, 'orderby' => 'menu_order', 'numberposts' => 1) )
    
        if( is_page_template( 'children-redirect.php' ) )
            wp_redirect( get_permalink( $child[0]->ID ) ); // redirect to first child page
    }
    add_action('template_redirect', 'children_redirect');
    

    [untested!]