Walker_Nav_Menu creating too many closing tags?
Remove the line $output .='</li>’; from your walker. The closing </li> is automatically entered by wordpress for every item. This is done in end_el function of the Walker_Nav_Menu class.
Remove the line $output .='</li>’; from your walker. The closing </li> is automatically entered by wordpress for every item. This is done in end_el function of the Walker_Nav_Menu class.
Sry, here is my answer: Here is first the output for listing the category in checkbox: Walker for the Category Output class Adv_Multicheck_Walker_Category extends Walker { var $tree_type=”category”; var $db_fields = array (‘parent’ => ‘parent’, ‘id’ => ‘term_id’); function start_lvl($output, $depth, $args) { if ( ‘list’ != $args[‘style’] ) return $output; $indent = str_repeat(“\t”, $depth); … Read more
Filter ‘wp_nav_menu_objects’ would help: add_filter( ‘wp_nav_menu_objects’, ‘remove_sub_items’, 10, 2 ); function remove_sub_items( $items,$args ) { $new_items = array(); for ($i=1;$i<count($items)+1;$i++){ //is lvl0 if(empty($items[$i]->menu_item_parent)){ $new_items= array_merge($new_items, nav_tree($items[$i],$items)); } } // var_dump($new_items); die(); if( $args->theme_location == ‘primary’ ) return $new_items; return $items; } function nav_tree($parent,$items){ $rtn = array(); $rtn[] = $parent; //Edit this conditional, return menu level … Read more
Inside the function your $x is local. You might want to use a static variable: class Walker_Nav_Menu_Costum extends Walker_Nav_Menu { static $x = 0; function end_el( &$output, $item, $depth = 0, $args = array() ) { if ( 1 == $depth ) self::$x++; $output .= “<!– x:”.self::$x.”–>”; $output .= “</li>\n”; } }
You can get a Menu’s entire item list with wp_get_nav_menu_items(). Then, loop through them all and test against the current post_id, and voila, you have all your data. <?php $menu_items = wp_get_nav_menu_items( ‘main-menu’ ); foreach( $menu_items as $item ) { print_r( $item ) ; // see what you can work with // carry on }
Consider this a complement to toscho’s solution. I believe that … $this->alternate = ($this->alternate != ‘background_1’) ? ‘background_1’ : ‘background_2′; $css_class[] = $this->alternate; … will do what you want. The difference is that toscho’s solution, using the static keyword, will make that variable static for any instantiation of this walker– that is, all instances will … Read more
I don’t have the time to work out a complete solution (which could be pretty complex) but, if I am reading things right, by default WordPress uses Walker_Nav_Menu_Edit to create those backend menus. It looks to me like you can build your own walker for the backend and pass it in via the wp_edit_nav_menu_walker hook. … Read more
Its in the wp_nav_menu arguments: ‘items_wrap’ => ‘<ul>%3$s<span></span></ul>’
this time my question is which walker class compatible with this menu structure Yes, you should be able to produce a walker to do that, but if you want markup completely different from what the menu API creates, why are you using the menu API? It is a waste of effort. However, what I would … Read more
Use the items_wrap argument (see codex). wp_nav_menu( array( ‘items_wrap’ => ‘<ul>%3$s</ul>’, ) )