So this is different from your code (and the one in the accepted answer to the other question), but it worked well for me:
You can remove the "\t" .
and . "\n"
which I added for pretty formatting purposes so that you could better inspect the generated HTML markup. And let me know if you have any question on any parts of the code. 🙂
// First, define these.
$max_cat_count = 32; // this is 'x'
$qty_per_column = 8; // this is 'y'
// Then the $args array.
$args = array(
'taxonomy' => 'product_cat',
'number' => $max_cat_count + 1, // keep the + 1
'title_li' => '',
'hide_empty' => 0,
'echo' => 0,
'style' => '',
// ... your other args here ...
);
// Get the categories list.
$get_cats = wp_list_categories( $args );
// Split the list into array items.
$cat_array = explode( "<br />", $get_cats );
$total = count( $cat_array );
$list_number = 1;
$_new_col = false;
foreach ( $cat_array as $i => $category ) {
if ( $i >= $max_cat_count ) {
break;
}
if ( $i % $qty_per_column === 0 ) {
// Close previous column, if any.
if ( $_new_col ) {
echo '</div><!-- .cat_columns -->' . "\n";
}
// Open new column.
$id = 'cat-col-' . $list_number;
echo '<div class="cat_columns" id="' . $id . '">' . "\n";
$_new_col = true;
$list_number++; // increment the columns count
}
if ( $total > $max_cat_count && $i === $max_cat_count - 1 ) {
// Make sure to change the # to the proper URL.
echo "\t" . '<div><a href="#">View All</a></div>' . "\n";
} else {
echo "\t" . '<div>' . trim( $category ) . '</div>' . "\n";
}
}
// Close last column, if any.
if ( $_new_col ) {
echo '</div><!-- .cat_columns -->' . "\n";
}