Creating Number Count on List
-
Hi,
I have a piece of code which I’m using to add a sequential number to each item in a list. The reason for this is because the graphic designer for the project wants a different background item for everything in the list, and doing this works perfectly for me. However, a problem has arisen as the code was being used for just a one-level list. Now, it’s got two levels but I don’t want the child list items to be included in the count. Does anyone know how I could change this code so that it only counts items in the parent list?Here’s my code at the moment:
$navcount = wp_nav_menu( array( 'theme_location' => 'Top Bar', 'menu' => 'Main Menu', 'depth' => 2, 'container' => false, 'echo' => false, 'menu_class' => 'nav' ) ); $nav_bits = explode('<li ', $navcount); $navcount = ''; $i = 0; foreach($nav_bits as $bits) : if($i==0) { $navcount = $navcount.$bits; } else { $navcount = $navcount.'<li class="item'.$i.'" '.$bits; } $i++; endforeach; echo $navcount;
Thanks!
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Creating Number Count on List’ is closed to new replies.