Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #1406797

    Hi All, I have a client that would like to have a select field on the page using a custom template – allowing them to select the main menu to be displayed. I’m using Advanced Custom Fields plugin for the select field. I have created a page template based on the template-builder.php. The new template calls a custom header file (copy of header.php) that finally calls “helper-custom-menu” (instead of “helper-main-menu”). I think I found the area where I need to change the code to make this all work, but it surely does NOT work. Does anyone have any suggestions on what needs to be changed for this to work correctly? Here’s the code section I changed:

    
                            /*
                            *   display the main navigation menu
                            *   modify the output in your wordpress admin backend at appearance->menus
                            */
                                if( $headerS['bottom_menu'] )
                                {
                                    $output .= '</div>';
                                    $output .= '</div>';
    
                                    if( ! empty( $headerS['header_menu_above'] ) )
                                    {
                                        $avia_config['temp_logo_container'] = "<div class='av-section-bottom-logo header_color'>{$output}</div>";
                                        $output = '';
                                    }
    
                                    $output .= "<div id='header_main_alternate' class='container_wrap'>";
                                    $output .= "<div class='container'>";
                                }
    
                                $avia_theme_location = 'avia';
                                $avia_menu_class = $avia_theme_location . '-menu';
                                $select_menu = the_field( 'select_wp_menu' )
    
                                $main_nav = "<nav class='main_menu' data-selectname='" . __( 'Select a page', 'avia_framework' ) . "' " . avia_markup_helper( array( 'context' => 'nav', 'echo' => false ) ) . '>';
    
                                $args = array(
                                            'theme_location'    => $avia_theme_location,
                                            'menu'              => $select_menu,
                                            'menu_class'        => 'menu av-main-nav',
                                            'container_class'   => $avia_menu_class.' av-main-nav-wrap'.$icon_beside,
                                            'items_wrap'        => '<ul role="menu" class="%2$s" id="%1$s">%3$s</ul>',
                                            'fallback_cb'       => 'avia_fallback_menu',
                                            'echo'              =>  false,
                                            'walker'            => new avia_responsive_mega_menu()
                                        );
    
                                    $wp_main_nav = wp_nav_menu( $args );
                                    $main_nav .= $wp_main_nav;
    
    #1407257

    Hey Jeffsne2,
    Thank you for your patience, I don’t have experience with ACF and am not sure what to change in your code above, but I do have a function that will set the menu based on the page ID, perhaps examining this will help point you in the right direction:
    This is for the main menu:

    function av_different_menu( $args = '' ) {
      if(is_page('591') && $args['menu_id'] == 'avia-menu') {
          $args['menu'] = '21';
      } 
      return $args;
      }
    add_filter( 'wp_nav_menu_args', 'av_different_menu' );

    this is for the topbar secondary menu

    function av_different_menu( $args = '' ) {
      if(is_page('591') && $args['theme_location'] === 'avia2') {
          $args['menu'] = '11';
      } 
      return $args;
      }
    add_filter( 'wp_nav_menu_args', 'av_different_menu' );

    I have also submited your question to our Slack channel, for further input, Thanks for your patience.

    Best regards,
    Mike

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.