How can I have my category widget display it's categories in multiple columns?
It appears others have done something like the below code. However, I'm not sure where this would go?
Thanks in advance!
<?php
$get_cats = wp_list_categories( 'echo=0&title_li=&depth=1&hide_empty=0' );
// Get cats
$cat_array = explode('</li>',$get_cats);
// Split into array items
$columns = 4;
// How many columns (virtual)
$cats_shown = 0;
// Don't touch this, this is just a counter (used below)
echo '<ul style="display:inline;">';
foreach($cat_array as $category) {
$cats_shown++;
// The 2 lines below can be removed if you apply the style definitions to the classes (ie. cat-item, cat-item a etc..)
// This was just quicker and easier for me to use whilst testing the code.
$category = str_replace('<li','<li style="display:inline"',$category);
$category = str_replace('<a href','<a style="width:160px;display:block;float:left" href',$category);
if($cats_shown % $columns == 0) {
// If the counter is a multiple of the columns to show
print $category.'</li></ul><br /><ul style="display:inline;">';
}
else {
// Else just a regular item
print $category.'</li>';
}
}
echo '</ul>';
?>