allienworks
2/16/2015 - 11:25 PM

Custom list categories template (with sub-cat post counts)

Custom list categories template (with sub-cat post counts)

<?php // Custom category list (w/ subcat counts)
	$args = array(
        'hide_empty'  => 0,  
        'orderby'     => 'name',
        'order'       => 'ASC',
        'taxonomy'    => 'category',
        'pad_counts'  => 1
    );

    //I'll leave it to you to check for error objects etc.
    $categories = get_categories($args);
    $categories = wp_list_filter($categories,array('parent'=>0));
    
    foreach ($categories as $cat) {
	    echo "<li class='category'><a href=\"".get_home_url()."/category/".$cat->category_nicename."\"><span class='count'>".$cat->category_count."</span></a>&nbsp;<a href=\"".get_home_url()."/category/".$cat->category_nicename."\">".$cat->cat_name."</a></li>";
	} ?>