カテゴリ表示について

<?php
$cat = get_query_var( 'cat' );
$now_cat = get_the_category();
$args = array(
'orderby'=>'slug',
'get'=>'all'
);
$cat_list = get_terms('category',$args);
//print_r($cat_list);
$cat_num = $now_cat[0]->category_parent;
if( $cat_num == "0" ){
	echo "<h3>" .$now_cat[0]->name. "</h3>\n";
	echo "<ul>\n";
	foreach($cat_list as $cat_title){
		if($cat_title->parent == $now_cat[0]->term_id){
			if( $cat_title->count != "0"){
			echo "<li".$onb."><a href='?cat=".$cat_title->term_id."'>".$cat_title->name."</a></li>\n";
			}else{
			echo "<li>".$cat_title->name."</li>\n";
			}
		} 
	}
}else{
	foreach($cat_list as $cat_title){
		if($cat_title->term_id == $cat_num) echo "<h3>" .$cat_title->name."</h3>\n";
	}
	echo "<ul>\n";
	foreach($cat_list as $cat_title){
		if($cat_title->parent == $cat_num){
			if( $now_cat[0]->term_id == $cat ){
			$onb = " class='on'";
			}
			if( $cat_title->count != "0"){
			//echo $cat_title->name."\n";
			echo "<li".$onb."><a href='?cat=".$cat_title->term_id."'>".$cat_title->name."</a></li>\n";
			}else{
			echo "<li>".$cat_title->name."</li>\n";
			}
		}
	}
}//endif
echo "</ul>\n";
 ?>

ごちゃごちゃしてるからこれはまだ整理できるはず。
get_termsは面白いなぁ。