as far as I know, all menu items already have unique ID´s (“menu-item-XX”), may they be first or second level. the UL itself has a different class :
menu
for first level and sub-menu
for second.
hence , in css for example
.menu li
and .sub-menu li
will give you the differentiation for styling.
you could also do that without the unique id or classes , by simply targeting the different levels of the menu,
.menu UL LI
for first level .menu UL LI UL LI
for second
Anotehr alternative is to use javascript or jQuery.. But I think this is not what you want here ..
EDIT I I forgot to mention that one can also add classes in the menu editor itself on item base , and also the has class arguments..Not to mention the fact that you can create 2 custom-menus wih your name*
EDIT II If you really want a custom function (everyone these days wants one..) than this one will add a class to each menu item which is equal to the menu title.
add_filter('nav_menu_css_class', 'dl_menu_class_by_title', 10, 2 );
function dl_menu_class_by_title($classes, $item) {
$classes[] = $item->title;
return $classes;
}
.. But I still stand by my first answer that in 98% of the cases – it is an unnecessary overkill ..
Edit III – since you are unable to implement none of the above ways to solution (all valid) – Here is The jQuery way :
<script>
$(function(){
var i =0;
$('ul.sub-menu').addClass (function(idx) {
return "item-" + idx;
});
});
</script>