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.

OK I just started using WordPress not very good and I have a menu problem I can REALLY use some help please.

I am working on a website and it has multiple locations, and not all the locations sell the same products. All the locations are pages with a parent structure.

Ohio -Contact Us -About us -Products etc...

West Virginia -Contact Us -About us -Products etc...

Pennsylvania -Contact Us -About us -Products

etc...

I got the hang of custom page templates and adding a custom menu to them (so all my Ohio pages use a custom Ohio template i made and included a custom Ohio menu).

I am using posts to create the product information pages and display them using:

*post_type="post" taxonomy="category" posts_per_page="10" tax_term=*

which seems to work out nice on a general product page, (especially since i would like to only create the product pages once sine there are a lot of them) but i cant figure out how to add a custom menu based on the parent pages they came from.

So if they come from my custom Ohio page and click on the link to a product post, there is not menu since that product might also be in West Virginia but not in Pennsylvania, so i cant use a standard menu.

Any way to get the parent info from where they just came from or something?

Any thoughts?

I am really new at WordPress coding so please be gentle

share|improve this question
    
Is this your question? Any way to get the parent info from where they just came from or something? –  Brad Dalton Jan 20 at 3:24
    
Yea basically, i need to know if there is a way to see what parent them came from to build a custom menu based on that –  Chris Jan 20 at 3:26
add comment

1 Answer

Can I confirm that you've actually created separate sub-pages for these duplicate products under each state?

Assuming that's true, you could use what I call a "soft-system" approach and use a naming convention. If you included Ohio in the page name (again, assuming post-name is part of your permalink structure, which is better for SEO anyway...), you could conditionally test for page name. this becomes a little more functional if your naming convention dictates that your product page will begin with the parent state.

xyz.com/ohio-product-1

then you have many ways to strip the significant portion of the uri prior to the first dash.

forgive my lack of code. I can always provide a basic example.

This is not the most Object Oriented approach, but if you're new to WP and you're not terrific with PHP my solution might be good for you.

Otherwise, try this:

http://wordpress.org/support/topic/how-to-get-top-level-parent-pages

Or, you could always use this WP function:

get_post_ancestors();

"Returns Array of IDs or empty if no ancestors are found. The direct parent is returned as the first value in the array. The highest level ancestor is returned as the last value in the array."

You would of course still end up with a conditional statement, such as:

$ancestry = get_post_ancestors( $post );
if( isset($ancestry) && !empty($ancestry)){
    $last = count($ancestry) - 1;
    $menu_per_state = get_the_title( $ancestry[ $last ] ); //uses ID 

    // relies on matching name for menu and page title using this method. 
    // uses default theme_location since none specified
    // refer to docs on wp_nav_menu, very helpful

    wp_nav_menu( array('menu' => $menu_per_state) );  
}
share|improve this answer
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.