How can I get an item counter working in a custom walker ?
I need the corresponding number (not the id) of each menu item for some class names, because my elements have position:absolute and each one has its class (class_name_1, class_name_2, ...) with individual top margins. I'm not using CSS3, so I can't use the nth-child pseudo class.
Thanks in advance !
EDIT: I managed to achieve this using (modified from example on codex):
if (($locations = get_nav_menu_locations()) && isset($locations[$menu_name]))
{
$menu = wp_get_nav_menu_object( $locations[ $menu_name ] );
$menu_items = wp_get_nav_menu_items($menu->term_id);
$menu_list = '<div id="side_menu">';
$current_item = 1;
foreach ( (array) $menu_items as $key => $menu_item )
{
$title = $menu_item->title;
$url = $menu_item->url;
$menu_list .= '<a class="tab_'.$current_item.'" href="'.$url.'"><span>'.$title.'</span></a>';
$current_item += 1;
}
$menu_list .= '</div>';
}
else
{
$menu_list = '';
}
Anyway, a solution to do this with the walker may be useful in the future. Thanks !