Hi,
I am new here and using Local by Flywheel to try out Bedrock, Sage 9, and Soil plugin (installed and activated) using UIKit CSS framework.
Everything is good until I got stuck in the menu section, basically having difficulty adding a new UIKit Walker.
Below are the two files of my current progress:
-
header.blade.php inside partials folder
<header class="banner"> <div class="uk-container uk-container-expand"> <nav class="uk-navbar-container" uk-navbar> <div class="uk-navbar-left"> <!-- <a class="brand" href="{{ home_url('/') }}">{{ get_bloginfo('name', 'display') }}</a>--> <a class="uk-navbar-item uk-logo" href="#"><img src="@asset('images/nomis-blue-logo.png')"></a> </div> <div class="uk-navbar-right"> @if (has_nav_menu('primary_navigation')) {!! wp_nav_menu([ 'theme_location' => 'primary_navigation', 'menu_class' => 'uk-navbar-nav uk-visible@m', 'walker' => new App\Controllers\UIKit_Walker ]) !!} @endif </div> </nav> </div> </header>
-
UIKit_Walker.php inside of app/Controllers folder
<?php namespace App\Controllers; /* Add UIkit classes to menu*/ class UIKit_Walker extends Walker_Nav_Menu { // add classes to ul sub-menus function start_lvl( &$output, $depth = 0, $args = array() ) { // depth dependent classes $indent = ( $depth > 0 ? str_repeat( "\t", $depth ) : '' ); // code indent $display_depth = ( $depth + 1); // because it counts the first submenu as 0 $classes = array( 'sub-menu', ( $display_depth % 2 ? 'menu-odd' : 'menu-even' ), ( $display_depth >=2 ? 'sub-sub-menu' : '' ), 'menu-depth-' . $display_depth ); $class_names = implode( ' ', $classes ); // build html if( $depth == 0 ) $output .= "\n" . $indent . '<div class="uk-navbar-dropdown" uk-drop="boundary: .uk-navbar; boundary-align: true; align: right; pos: bottom-justify; offset: 0;delay-hide:100"><ul class="uk-nav uk-navbar-dropdown-nav uk-grid-medium uk-grid uk-child-width-expand" >' . "\n"; if( $depth > 0 ) $output .= "\n" . $indent . '<div><ul class="uk-nav uk-navbar-dropdown-nav">' . "\n"; } function end_lvl(&$output, $depth=0, $args=array()) { $output .= "</ul></div>\n"; } // add main/sub classes to li's and links function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { global $wp_query; $indent = ( $depth > 0 ? str_repeat( "\t", $depth ) : '' ); // code indent // depth dependent classes $depth_classes = array( ( $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ), ( $depth >=2 ? 'uk-nav-cat-sub' : '' ), ( $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ), 'menu-item-depth-' . $depth ); $depth_class_names = esc_attr( implode( ' ', $depth_classes ) ); // passed classes $classes = empty( $item->classes ) ? array() : (array) $item->classes; $class_names = esc_attr( implode( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) ) ); // build html $output .= $indent . '<li class="' . $depth_class_names . '">'; // link attributes $attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : ''; $attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : ''; $attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : ''; $attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : ''; $attributes .= ' class=""'; $description .= ! empty($item->description) ? '<span class="uk-text-small uk-menu-description">' . esc_attr( $item->description ) . '</span>' : ''; $format = '%1$s<a%2$s><div>%3$s%4$s%5$s</div></a>%6$s'; if( $depth == 1 ) $format = '%1$s<a%2$s><div class="uk-nav-cat-header">%3$s%4$s%5$s</div></a>%6$s'; $item_output = sprintf( $format, $args->before, $attributes, $args->link_before, apply_filters( 'the_title', $item->title, $item->ID ), $description, $args->link_after, $args->after ); // build html $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); } }
In my previous non-Sage Wordpress project, I would place the class UIKit_Walker extends Walker_Nav_Menu in functions.php and it will work.
However, in Sage theme, below is the error that i am getting:
Please advise. Thanks!