I have a small function in my WordPress theme which generates a list of menus depending on category id. I have also setup an even/odd identifier to add spacers in between, the last one is removed via jQuery (unless you can provide a way of doing this in PHP code).
Each menu shows the spacers accordingly apart from one random one?
function momentmag_tertiary_nav($cat_ID, $name = '') {
$categories = get_categories( array('child_of' => $cat_ID, 'hide_empty' => false) );
$siteurl = get_bloginfo('url');
$i = count($categories);
$catparent = get_categories( array('include' => $cat_ID, 'hide_empty' => false) );
echo '<ul class="'.$name.'-drop">';
foreach($categories as $category) {
echo '<li><a href="'.$siteurl.'/'.$catparent[0]->slug.'/'.$category->slug.'" title="View Articles in: '.$catparent[0]->cat_name.' → '.$category->cat_name.'">'.$category->cat_name.'</a></li>';
if ($i % 2 != 0) {
echo '<li class="spacer"></li>';
}
}
echo '</ul>';
}
Example of working menu:
Then this one randomly doesn't apply the spacers where as all the others do, there is 10 in total:
any ideas? this is really dodgy!