Coder Social home page Coder Social logo

Submenu doesn't work about mdlwp HOT 3 CLOSED

braginteractive avatar braginteractive commented on August 16, 2024
Submenu doesn't work

from mdlwp.

Comments (3)

braginteractive avatar braginteractive commented on August 16, 2024

Material Design Lite doesn't have styling for submenus.

from mdlwp.

Rambou avatar Rambou commented on August 16, 2024

Yes i know although one way to add submenu to this theme which is needed and there is an option on wordpress is like this.

<nav respond-plugin type="menu" menu="primary" class="mdl-navigation mdl-layout--large-screen-only">

                <li id="home" class="mdl-navigation__link" >Link 1</li>
                <a class="mdl-navigation__link" href="page/news.html">Link 2</a>
                <a class="mdl-navigation__link" href="#">Link 3</a>

                <!-- sub menu only visible when clicked on the link above -->
                <ul class="mdl-menu mdl-menu--bottom-left mdl-js-menu mdl-js-ripple-effect"
                    for="home">
                    <a class="mdl-menu__item" href="index.html">SubLink 1</a>
                    <a class="mdl-menu__item" href="index.html">SubLink 2</a>
                </ul>
........

The question is how to edit the Custom nav_walker to make support this?

from mdlwp.

Rambou avatar Rambou commented on August 16, 2024

Anyway i did some changes in your nav_walker class and hope that now it should work like a charm. I will make a pull request soon.
image

	function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
		global $previous;

		$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';

		$class_names = $value = '';

		$classes = empty( $item->classes ) ? array() : (array) $item->classes;
		$classes[] = 'menu-item-' . $item->ID;

		$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );

		if ( in_array( 'current-menu-item', $classes ) )
				$class_names .= ' is-active';

		$class_names = $class_names ? ' class="mdl-navigation__link ' . esc_attr( $class_names ) . '"' : '';

		$id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args );
		$id = $id ? ' id="' . esc_attr( $id ) . '"' : '';

		$output .= $indent . '';

		$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 .= ($item->menu_item_parent)? (! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : ''): '';
		$attributes .= ! empty( $item->ID )        ? ' id="'   . esc_attr( $item->ID        ) .'"' : '';
		if ($item->menu_item_parent){
			$attributes .= 'class="mdl-menu__item"';
	  }else{
			$attributes .= $class_names;
		}


		$item_output = $args->before;

		if (!$item->menu_item_parent && $previous->menu_item_parent){
			$item_output .= '</ul>';
		}

		if ($item->menu_item_parent && !$previous->menu_item_parent){
			$item_output .= '<ul class="mdl-menu mdl-menu--bottom-left mdl-js-menu mdl-js-ripple-effect" for="'. $item->menu_item_parent.'">';
		}
		$item_output .= '<a'. $attributes .'>';
		$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
		$item_output .= '</a>';
		$item_output .= $args->after;


		$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
		$previous = $item;
	}

from mdlwp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.