I have written a custom walker that I am using with wp_nav_menu but I need to iterate through 4 custom classes, and I'm not sure how to do this. Basically, each menu-item <li> needs to be given a class of color1, color2, color3 or color4, cycling back to color1, lather, rinse, repeat, in that order.

Ordinarily I would do this with a $i and a $i++, but how do I do this in the Walker class?

There're already too many globals and conflicts are just about to happen. If you add a global, then only if you really have to and even then, you should prefix it.
–
kaiser♦Feb 3 '12 at 16:02

Fair enough. The other answer is more elegant, but mine still solves the problem - not sure if it warrants a downvote... I will say that the likelihood of $color_num conflicting is really low, especially in the scope of any process that this walker would be run in.
–
Drew GourleyFeb 3 '12 at 17:05

Just a sidenote: Instead of calling get_post_meta() several times, you can also do extract( get_post_custom( $post->ID ), EXTR_SKIP ); which gives you the same vars you used with a simple one-liner. Oh, and you're missing a space between the classes: "active color' . $ac_color_num . '".
–
kaiser♦Feb 3 '12 at 19:44

1

That's a nice move with get_post_custom - I was just doing a copypasta of her code and adding my stuff in. the lack of a space is so the class is color3 instead of color 3 - I'm just outputting the number.
–
Drew GourleyFeb 3 '12 at 22:08