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 see that in menu exist to kind of hierarchy to find the parent and ancestor.

They look for "category or page" hierarchy or for "menu item" hierarchy.

But when both exist in a depth tree branch, they dont work well.

e.q. IN menu tree

• Page 1
  • Category 1
  • Page 2
• Page 2

IN admin real hierarchy

• Category 1 > • Post 1

• In this case, if I am in (frontoffice) "Category 1" it's parent in menu tree, "Page 1", has class "current-menu-ancestor current-menu-parent"

• If I am in Post 1 (frontoffice) within "Category 1" this one has "current-post-ancestor current-menu-parent current-post-parent". But the "Page 1" even if have not direct connection with Post 1, still are parent of "category 1". But it's not marked as Parent or ancestor.

I try by custom walker or even filter the "nav_menu_css_class" to find way that check,

if any child of current is ancestor this is ancestor too. We have to check menu tree or real admin tree, category or page.

Because if level 2 it's ancestor level 1 should be too.

share|improve this question
1  
Inside Category 1 not menu child? Say what? Are you saying IF you are VIEWING a POST inside Category 1, but did not get there via the navigation menu E.g. Page -> Category 1 -> Post THEN Page 1 does not show current-post-ancestor class, is that correct? Just trying to follow here... –  userabuser Oct 10 '12 at 14:53
    
the menu tree is 'Page -> Category 1' and the 'Post1' are in 'Category 1'. When u are in Post1, the 'Category 1' are highlight but 'Page 1' not –  gaspas Oct 10 '12 at 15:04
    
Ah, you want to highlight all ancestors/parents of a "current menu item" in your nav menu, right? –  kaiser Oct 10 '12 at 21:56
add comment

1 Answer

This is correct behavior as far as I can tell,

Imagine a scenario where you have a menu with top level items, Page A and Page B, each of which have Category 1 attached as a sub-menu item.

Scenario 1


When viewing Post Example X, Attached to Category 1 And Where Category 1 appears twice in the menu under different top level items, we see;

/*
- Page A              = no ancestor class!
  - Category 1        = current-menu-ancestor, current-menu-parent, current-post-parent
- Page B              = no ancestor class!
  - Category 1        = current-menu-ancestor, current-menu-parent, current-post-parent
*/

If you view a Post, let's call it Post Example X, then which top level menu item should receive the current-menu-ancestor class?

  1. Should it be both Page A and Page B?
  2. Should it be Page A?
  3. Should it be Page B?

WordPress decides neither. Its better not to assume what the users intent is unless specified differently, otherwise if you have special styling associated with that class then it would be applied to all top level menu items and beyond causing unexpected results.

But if you say to me that Category 1 only appears beneath Page A top level menu ONLY and no where else, it still doesn't matter... check out these scenarios.

Scenario 2


When viewing Post Example X, Attached to Category 1 Where Post Example X does NOT appear in the same menu tree as the top level Page A or any other top level tree, we see;

/*
- Page A              = no ancestor class, still!
  - Category 1        = current-menu-ancestor, current-menu-parent, current-post-parent
- Page B              = not related to post
  - Category 2        = not related to post
*/

Scenario 3


When viewing Post Example X which is also, Attached to Category 1 or in the same tree as the top level Page A, we see;

/*
- Page A              = current-menu-ancestor
  - Category 1        = current-menu-ancestor, current-menu-parent, current-post-ancestor, current-post-parent
    - Post Example X  = current-menu-item
- Page B              = not related to post
  - Category 2        = not related to post
*/

Scenario 4


When viewing Post Example X which is also, Attached to Category 1 or in the same tree as the top level Page A but where Category 1 also appears beneath Page B but itself does not contain our post, we see;

/*
- Page A              = current-menu-ancestor
  - Category 1        = current-menu-ancestor, current-menu-parent, current-post-ancestor, current-post-parent
    - Post Example X  = current-menu-item
- Page B              = not related to post
  - Category         = current-menu-ancestor, current-menu-parent, current-post-parent
*/

I'm just writing this to give a general idea how it works, next I'll take a look at the filters for nav_menu_css_class and wp_get_nav_menu_items.

My understanding behind the logic of the menu handling process is a bit fuzzy, possibly someone else will jump in and help too in the meantime.

share|improve this answer
    
Yes I follow on trac some tickets I see that is the expected behavior. Scenario 1 It happens the same if u have a page duplicate in the menu. All parent are marked. Or if 'PAGE A1' are a 'SUB-PAGE' of 'PAGE A' and in the MENU the 'PAGE A1' are only child of 'PAGE B' 'PAGE A' has class 'current-page-parent' and 'PAGE B' has class 'current-menu-parent' What I expected to be the right behaviour in case of the 'POST X' Attached to 'CATEGORY 1' in Scenario 1 is that 'PAGE A' have a class e.q. current-pseudo-parent-menu –  gaspas Oct 11 '12 at 8:13
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.