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 !

link|improve this question
1  
Would be helpful to see the code you need the counter in. – t31os Aug 5 '11 at 10:40
I was trying to modify (simplify) this example wpcodesnippets.info/blog/lets-put-icons-in-our-menus.html . However, in the mean time, I used the example from the wordpress codex on wp_get_nav_menu_items(). – Mio Aug 5 '11 at 11:19
1  
How does the above code relate to the link you've provided, sorry i don't follow... (can you not simply do as you've done above inside the custom walker?) ... – t31os Aug 5 '11 at 11:37
They are related in the way that the same thing can be achieved in two different ways. My goal was to render the items in a menu with custom markup. The specific need was for a counter. So, yes, I can and I have done as above. As I said in the edit, answer for my initial question remains useful for future reference. – Mio Aug 5 '11 at 12:38
feedback

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
or
required, but never shown

Browse other questions tagged or ask your own question.