Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with active ancestors not reflecting WP built-in classes #91

Open
codewithfeeling opened this issue Feb 10, 2025 · 2 comments
Open

Comments

@codewithfeeling
Copy link

I'm using Navi to render 2 menus in the header - one is a submenu for various photo albums when the user selects Photographs in the main menu.

My problem is that although the submenu nav items are all child pages of the Photographs parent, this main menu item is never getting attributed as being an active ancestor.

When I build the menus with default classes, I can see that current-page-ancestor is in there, yet Navi is not picking that up when I visit my local URL http://mysite.test/photographs/nature

Here's the "Nature" nav item dump - active is correctly showing up

{#1311 ▼ // resources/views/components/nav-item.blade.php
  +"active": true
  +"activeAncestor": false
  +"activeParent": false
  +"classes": " menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-1151 current_page_item"
  +"dbId": 1727
  +"description": false
  +"id": 1727
  +"label": "Nature"
  +"object": "page"
  +"objectId": "1151"
  +"order": 2
  +"parent": false
  +"slug": "1727"
  +"target": false
  +"title": false
  +"type": "post_type"
  +"url": "http://leo.test/photographs/nature/"
  +"xfn": false
  +"parentObjectId": false
  +"children": []
}

Here's the Photographs item dump - absolutely nothing to show it is part of the hierarchy - but look at the built-in classes - correctly showing current-page-ancestor

{#1419 ▼ // resources/views/components/nav-item.blade.php
  +"active": false
  +"activeAncestor": false
  +"activeParent": false
  +"classes": " menu-item menu-item-type-post_type menu-item-object-page current-page-ancestor"
  +"dbId": 1330
  +"description": false
  +"id": 1330
  +"label": "Photographs"
  +"object": "page"
  +"objectId": "1051"
  +"order": 3
  +"parent": false
  +"slug": "1330"
  +"target": false
  +"title": false
  +"type": "post_type"
  +"url": "http://leo.test/photographs/"
  +"xfn": false
  +"parentObjectId": false
  +"children": []
}

Is this a bug?

@Log1x
Copy link
Owner

Log1x commented Feb 11, 2025

perhaps https://github.com/Log1x/navi/blob/master/src/MenuBuilder.php#L17-L18 needs adjusted to reflect different classes? 🤔

@codewithfeeling
Copy link
Author

Thanks - I'll have a play with that - thanks for the pointer. I just wondered if it was a bug or just not part of what MenuBuilder is looking for when building the classes out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants