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.

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.

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?

share|improve this question
    
add comment

1 Answer

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!]

share|improve this answer
2  
+1 Even better would be to hook into template_redirect. –  kaiser Jul 31 '12 at 18:43
1  
Just to add - I use Page Links To to do 301 redirects on empty pages from the admin panel. wordpress.org/extend/plugins/page-links-to –  SickHippie Jul 31 '12 at 19:25
add comment

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.