I'm trying to list all terms on a custom taxonomy but I wanted to at least group them into 3 columns including their children to have a visual balance. Here's what I've done so far. I'm stuck on creating the loop after it reached the maximum term. On what I have, It wrapped all the succeeding items with 'ul' instead of creating a second ul and list the next batch. After it reaches the x amount of term it should create another 'ul' element listing categories in it. There will be a total of 3 columns.
<?php
$get_cats = wp_list_categories( 'echo=0&title_li=&depth=2&hide_empty=0,&taxonomy=industries' );
// Split into array items
$cat_array = explode('</li>',$get_cats);
// Amount of categories (count of items in array)
$results_total = count($cat_array);
// How many categories to show per list (round up total divided by 3)
$cats_per_list = ceil($results_total / 3);
// Counter number for tagging onto each list
$list_number = 1;
// Set the category result counter to zero
$result_number = 0;
?>
<?php echo $cats_per_list ; ?>
<ul class="cat_col" id="cat-col-<?php echo $list_number; ?>">
<?php
foreach($cat_array as $category) {
$result_number++;
if($result_number >= $cats_per_list) {
$list_number++;
echo $category.'</li> </ul> <ul class="cat_col" id="cat-col-'.$list_number.'">';
}
else {
echo $category.'</li>';
}
}
?>
</ul>