• Hi guys !

    I’m actually trying to create my own theme. For this, I use the framework Materialize. There isn’t the problem.

    To have a nice sidebar, I must get the output of wp_nav_menu() like this :

    <ul class='collapsible collapsbile-accordion'>
    	<li class='bold'>
    		<a class='collapsible-header waves-effect'>$object->title</a>
    		<div class='collapsible-body'>
    			<ul>
    				<li>
    					<a href='$object->url'>$object->title</a>
    				</li>
    			</ul>
    		</div>
    	</li>
    </ul>

    So, I tried to create a Walker that would make this work.

    class Sidebar_Walker extends Walker {
    
            function start_lvl( &$output, $depth, $args ) {
    
                if( $depth == 0 )
                    $output .= "<ul class='collapsible collapsbile-accordion'>";
                else
                    $output .= "<div class='collapsible-body'><ul>";
            }
    
            function end_lvl( &$output, $depth, $args )  {
    
                if( $depth == 0 )
                    $output .= "</ul>";
                else
                    $output .= "</ul></div>";
            }
    
            function start_el( &$output, $item, $depth, $args )  {
    
                if( $depth == 0 )
                    $output .= "<li class='bold'><a class='collapsible-header waves-effect'>".$item->title."</a>";
                else
                    $output .= "<li><a href='".$item->url."'>".$item->title."</a>";
            }
    
            function end_el( &$output, $item, $depth, $args ) {
    
                $output .= "</li>";
            }
    }

    I’m not confident in this code to work and, when I set the Walker as callback of wp_nav_menu(), I just get this error :

    Warning: Illegal offset type in D:\XAMPP\htdocs\DIVTEC\wp-includes\class-wp-walker.php on line 224.

    Line 224 is : $children_elements[ $e->$parent_field ][] = $e;

    Thanks for reading this, I hope that you can help me !

    (Sorry for english mistakes I could have done, it isn’t my main language)

  • The topic ‘Walker problem : Illegal offset …’ is closed to new replies.