Wordpress menu columns
static $counter;
static $childrenCount;
function display_element($element, &$children_elements, $max_depth, $depth = 0, $args, &$output)
{
$element->hasChildren = isset($children_elements[$element->ID]) && !empty($children_elements[$element->ID]);
$element->childrenCount = count( $children_elements[$element->ID] );
return parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output);
}
function start_el(&$output, $item, $depth, $args) {
if( $depth )
{
$this->counter += 1;
}else
{
$this->counter = 0;
$this->childrenCount = $item->childrenCount;
}
}
function end_el(&$output, $item, $depth) {
$output .= "</li>\n";
$theme_location = 'primary';
$theme_locations = get_nav_menu_locations();
$menu_obj = get_term( $theme_locations[$theme_location], 'nav_menu' );
if( $this->counter%5 == 0 and $this->counter != $this->childrenCount and $this->counter != 0 and $this->counter != $menu_obj->count )
{
$output .= '</ul><ul>';
}
}