
nested hierarchical category list
By:
alchymyth on
Feb 10th, 2012 | syntax:
PHP | size: 1.38 KB | hits: 274 | expires: Never
<?php
hierarchical_category_tree( 0 ); // the function call; 0 for all categories; or cat ID
function hierarchical_category_tree( $cat ) {
static $depth=0;
// wpse-41548 // v1.3 // structured nested list // alchymyth // a hierarchical list of all categories //
$next = get_categories('hide_empty=0&orderby=name&order=ASC&parent=' . $cat);
if( $next ) :
$depth++;
echo "\n"; for($i=1;$i<$depth;$i++) echo ' '; //for structured html output
echo '<ul class="depth-'.$depth.'">';
foreach( $next as $cat ) :
echo "\n "; for($i=1;$i<$depth;$i++) echo ' '; //for structured html output
echo '<li><strong>' . $cat->name . '</strong>';
echo ' / <a href="' . get_category_link( $cat->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $cat->name ) . '" ' . '>View ( '. $cat->count . ' posts )</a> ';
echo ' / <a href="'. get_admin_url().'edit-tags.php?action=edit&taxonomy=category&tag_ID='.$cat->term_id.'&post_type=post" title="Edit Category">Edit</a>';
hierarchical_category_tree( $cat->term_id );
echo '</li>';
endforeach;
echo "\n"; for($i=1;$i<$depth;$i++) echo ' '; //for structured html output
echo '</ul><!--/.depth-'.$depth.'-->';
$depth--;
echo "\n "; for($i=1;$i<$depth;$i++) echo ' '; //for structured html output
endif;
}
?>