• Is there a function to get a hierarchal list of a categories children/grandchildren/greatgrandchildren?

    For example, let’s say I have the categories like Things > Living Things > Animals > Cows, Pigs, Sheep

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi Oguruma,

    sure:

    1. Just go to Post -> Add New Category -> Creat Parent Category
    2. Go to Post -> Add new category -> choose Parent Category in the Dropdown

    And so on…

    https://stackoverflow.com/questions/51478592/show-wordpress-categories-as-hierarchical

    <?php
    	hierarchical_category_tree_09hy7( 0 ); // the function call; 0 for all categories; or cat ID  
    	function hierarchical_category_tree_09hy7( $cat ) {
    		$next = get_categories('hide_empty=0&orderby=name&order=ASC&parent=' . $cat);
    		if( $next ){   
    			foreach( $next as $cat ){
    				echo '<ul><li>' . $cat->name . '';
    				hierarchical_category_tree_09hy7( $cat->term_id );
    			}	
    		}
    		echo '</li></ul>'; echo "\n";
    	}  
    ?>

    seems to work on my localhost. Note the hide_empty=0 I’m using locally so it shows all even empty categories.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get Hierarchal list of categories?’ is closed to new replies.