OnPoint Plugins

  • Plugins
    • Advanced Sidebar Menu
    • Go Live Update Urls
  • About
    • Services
    • Showcase
  • Blog
  • Contact
  • Support
  • Log In
← Back to support

Hide non siblings of the current page

Resolved

Requested: 10 months and 4 days ago

Currently I have an advanced sidebar widget set up to display all of the menu items.
Is it possible, through customization or actions, to hide other ‘child-sidebar-menu’
and ‘children’ menu items that are not siblings of the current page?

The menu would just show all the top level items, with the current pages section
expanded, and all of the current page’s siblings, along with the current page’s
parents siblings also.

Here is a diagram to show what I mean: https://imgur.com/a/NvwEsVJ

Another example would be the side menu on this page:
https://www.vailhealth.org/community/classes/fitness

You can see in that menu above that only the current page’s immediate siblings and parents siblings are
visible, and all the other child menu items of the main (top) menu items are hidden .

I’m thinking that this action would possibly help – please let me know if I’m on the right track:
advanced-sidebar-menu/menus/navigation/objects/parse-hierarchy

add_action( ‘advanced-sidebar-menu/menus/navigation/objects/parse-hierarchy’, function( $hierarchy, $item, $class, $menu_items ) {
// Remove all children of an item by it’s menu item id.

//get current menu item id
//and somehow retrieve the menu item id’s of ‘child-sidebar-menu’ and ‘children’ items that are not siblings of the current page
unset( $class->hierarchy[5] );

}, 10, 4 );

Plugin: Advanced Sidebar Menu

  1. Deanne Holzman

    10 months and 4 days ago

    After more research, I found that conversely, instead of setting the ‘Navigation Widget’ to display all of the menu items, I could set it up to display only the current section navigation, and customize it with the action filter found in the below support request.  The only thing I’d like to do differently than this is to display all the Top Level menu items also, along with the ‘Current Section’ if that makes sense:

    https://onpointplugins.com/plugin-support/only-showing-children-of-current-page-using-pro-navigation-widget/
    add_action( ‘advanced-sidebar-menu/menus/navigation/objects/parse-hierarchy’, function ( array $hierarchy, $current, $objects ) {
    $allowed[0] = $hierarchy[0];
    if ( $current ) {
    if ( $current->get_parent() ) {
    foreach ( $objects->get_child_items_recursive( $current->get_id() ) as $_item ) {
    if ( isset( $hierarchy[ $_item->get_id() ] ) ) {
    $allowed[ $_item->get_id() ] = $hierarchy[ $_item->get_id() ];
    }
    }
    foreach ( $objects->get_parent_items_recursive( $current ) as $_item ) {
    if ( isset( $hierarchy[ $_item->get_id() ] ) ) {
    $allowed[ $_item->get_id() ] = $hierarchy[ $_item->get_id() ];
    }
    }
    } elseif ( isset( $hierarchy[ $current->get_id() ] ) ) {
    $allowed[ $current->get_id() ] = $hierarchy[ $current->get_id() ];
    }
    }
    $objects->hierarchy = $allowed;
    }, 10, 3 );

     

     

  2. OnPoint Plugins

    10 months and 4 days ago

    Hi Deanne,

    You may accomplish the same functionality as the “Display the current item’s section only” option as well as including the top level items by:

    1. Uncheck the “Display the current item’s section only” widget option.
    2. Add the following filter.

    Have a great weekend!

     

  3. Deanne Holzman

    10 months and 4 days ago

    Thanks a lot for your help!  I appreciate that filter – it’s very close to what we need to do, but I was wondering if it’s possible to show *just* the current item siblings, while hiding ‘cousin’ child menu items – if that makes sense.  We are anticipating alot of child menu items, and it would simplify our sidebar menu if we were able to do this – see an illustration of what I mean here:

    https://imgur.com/a/G9b6v29

     

  4. OnPoint Plugins

    10 months and 3 days ago

    Hi Deanne,

    This version of the filter will also remove grandchild items which are not siblings or children of the current item.

    Have a great day!

  5. Deanne Holzman

    10 months and 1 day ago

    I really appreciate your help – that is the configuration we need – thanks for a great plugin!

New Response Cancel reply

You must be logged in to respond. Only PRO members are allowed to respond to support requests.

© 2023 · WordPress Development · Terms Of Service · Privacy Policy · Cookie Policy · Log in

  • Plugins
  • Blog
  • Contact