View Single Post
Old 04-12-2012, 02:07 AM  
zerovic
Confirmed User
 
zerovic's Avatar
 
Industry Role:
Join Date: Apr 2010
Posts: 1,084
I've re-wrote the code for you, to make it work with 5 columns...

please note, if the total number is like 23, which can't be divided by 5, it will add more categories to the last column

Code:
	$catArray = explode("</li>",wp_list_categories('title_li=&echo=0&depth=1'));
	$catCount = count($catArray) - 1;
	$catColumns = round($catCount / 5);
	$catColumns_2 = $catColumns * 2;
	$catColumns_3 = $catColumns * 3;
	$catColumns_4 = $catColumns * 4;
	$catColumns_5 = $catColumns * 5;
	$i = 0;

	foreach($catArray as $categories) {
	if($i < $catColumns) {
	$first_column .= $categories . "</li>";
	$i++;
	} elseif($i < $catColumns_2) {
	$second_column .= $categories . "</li>";
	$i++;
	} elseif($i < $catColumns_3) {
	$third_column .= $categories . "</li>";
	$i++;
	} elseif($i < $catColumns_4) {
	$fourth_column .= $categories . "</li>";
	$i++;
	} else {
	$fifth_column .= $categories . "</li>";
	$i++;
	} }
 
?>


<ul class="first">
      <?php echo $first_column; ?>
</ul>
<ul class="second">
      <?php echo $second_column; ?>
</ul>
<ul class="third">
      <?php echo $third_column; ?>
</ul>
<ul class="fourth">
      <?php echo $fourth_column; ?>
</ul>
<ul class="fifth">
      <?php echo $fifth_column; ?>
</ul>
hope it's ok :P
__________________
php, html, jquery, javascript, wordpress - contact me at contact at zerovic.com

Last edited by zerovic; 04-12-2012 at 02:11 AM..
zerovic is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote