• I find and use the following code to display sub categories for default taxonomy ‘category’ on my site, but I created a custom taxonomy, and can not alter the code so that he was doing the same thing for the new taxonomy, help please

    <?php
    
    if(is_category()) {
    	$subcategories = get_terms('category', 'parent='.get_query_var('cat'));
    
    	if(empty($subcategories)) {
    		$thiscat = get_term(get_query_var('cat'),'category');
    		$subcategories = get_terms('category', 'parent='.$thiscat->parent.'');
    	}
    	if(empty($subcategories)) $subcategories = array();
    	if(!empty($subcategories)) {
    		echo '<ul>';
    
    		foreach($subcategories as $subcat) {
    			if(get_query_var('cat') == $subcat->term_id) $current = ' current-cat'; else $current = '';
    			echo '
    			<li class="cat-item cat-item-'.$subcat->term_id.$current.'">
    				<a href="'.get_category_link( $subcat->term_id ).'" title="'.$subcat->description.'">'.$subcat->name.'</a>
    			</li>';
    
    		}
    		echo '</ul>';
    	}
    }
    else {
    	// If no current cat query, just get the top level ones using wp_list_categories.
    	?>
    	<ul>
    		<?php wp_list_categories('title_li=&depth=1');?>
    	</ul>
    	<?php
    }
    ?>

  • The topic ‘Categories and Sub Categories in custom taxonomies….’ is closed to new replies.