• Resolved yourbudweiser

    (@yourbudweiser)


    I am setting up multiple menus using the Pages, Auto apply sub-pages conditions. After checking Auto apply sub-pages, the sub-pages are added but we are having an issue where sub-pages are loading menus which are not part of the selected parent.

    Example, from the main menu, hover over Levels of Care and select First Responders Treatment. Per the plugin settings, the menu on this page should only appear if it is a child of Locations, Cherry Hill, which it is not.

    Please help.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter yourbudweiser

    (@yourbudweiser)

    Please disregard this support request. I was able to code my own conditional menus using Advanced Custom Fields and an ACF Menu Field plugin.

    The idea here is that using ACF, the website administrator selects a Parent Page (ACF Post Object field) and then a corresponding menu (menu field plugin) to display if any sub-pages of the selected parent page is being viewed. Using a repeater, I was able to select as many parent pages as needed.

    Here’s my code if anyone else is interested:

    /**
     * Conditional menus based on page parent
     */
    
    function lhc_locations_menu( $args ) {
    
        global $post;
    
        if ( have_rows( 'locations_menu', 'options' ) ) :
            while ( have_rows( 'locations_menu', 'options' ) ) :
                the_row();
    
                $locations_parent_page = get_sub_field( 'locations_parent_page', 'options' );
                $locations_menu_id = get_sub_field('locations_menu', 'options');
    
                if ( $post->post_parent == $locations_parent_page->ID || is_page($locations_parent_page->ID) ) :
                    $menu_id = $locations_menu_id;
                endif;   
           
            endwhile;
        endif;
    
        $args['menu'] = $menu_id;
        return $args;
    }
    
    add_filter( 'wp_nav_menu_args', 'lhc_locations_menu' );
    Plugin Author themifyme

    (@themifyme)

    Hi @yourbudweiser

    I’m glad it’s resolved, if you need help with anything else, please open a new topic, so we can help you there.

    Have a good day!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Condition Pages, All Sub-Pages’ is closed to new replies.