View Single Post
Old 02-24-2012, 11:03 AM  
tonyparra
Confirmed User
 
tonyparra's Avatar
 
Industry Role:
Join Date: Jul 2008
Location: In your back seat with duck tape
Posts: 4,568
Wordpress Ninjas help please: Display categories in columns with post count

Trying to do something like at tubegalore.com where they show show a list of categories, in columns, with the number of videos per category but in wordpress obviously it would be post per category.

I found some php that will display 3 columns but im trying to find a better way

Code:
<?php							
	$catArray = explode("</li>",wp_list_categories('title_li=&echo=0&depth=1'));
	$catCount = count($catArray) - 1;
	$catColumns = round($catCount / 3);
	$twoColumns = round($catColumns + $catColumns);
 
	for ($i=0;$i<$catCount;$i++) {
		if ($i<$catColumns){
			$catLeft = $catLeft.''.$catArray[$i].'</li>';
	         }
		elseif ($i<$twoColumns) {
			$catMiddle = $catMiddle.''.$catArray[$i].'</li>';
		} 
		elseif ($i>=$catColumns){
			$catRight = $catRight.''.$catArray[$i].'</li>';
		 }  
	};
?>
 
<ul class="left">
      <?php echo $catLeft; ?>
</ul>
<ul class="middle">
	<?php echo $catMiddle; ?>
</ul>
<ul class="right">
      <?php echo $catRight; ?>
</ul>
__________________

High Performance Vps $10 Linode
Manage your Digital Ocean, Linode, or Favorite Cloud Server. Simple, fast, and secure Server Pilot
tonyparra is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote