Support » Plugins » Hacks » List of sub categories to create a catalog

Viewing 1 replies (of 1 total)
  • Hello didiair,

    You could get all the parent categories, then loop through them getting the children and displaying them how you want.

    //first get the category
    $args = array(
        'orderby'       => 'name',
        'order'         => 'ASC',
        'parent'         => 0
    );
    
    $terms = get_terms( 'category_taxonomy_name', $args ); //put category taxonomy name here
    
    //loop through categories
    if($terms){
        foreach($terms as $term){
            echo '<h2>' . $term->name . '</h2>';
            $term_children = get_term_children( $term, 'category_taxonomy_name' ); //place your category taxonomy name here
            if($term_children){
                foreach($term_children as $child){
                    echo '<h3>' . $child->name . '</h3>';
                    echo '<p>' . $child->description . '</p>';
                    echo '<a href="'.get_term_link($child->slug, 'category_taxonomy_name').'">'.$term->name.'</a>'; //place your category taxonomy name here
                }
            }//end children
    
        }//end categories
    }//end if categories
Viewing 1 replies (of 1 total)
  • The topic ‘List of sub categories to create a catalog’ is closed to new replies.