WordPress.org

Forums

wp_list_categories - print a tree (1 post)

  1. DrLightman
    Member
    Posted 3 years ago #

    Does it seem it cannot be done in a single call? Not that because is a single call it will be faster tho.

    Let's say I want to print category "Books" and its childs. I only came to this solution:

    $books_cat_id = 7;
    $childs = get_categories( array( 'child_of' => $books_cat_id ) );
    $ids = array( $books_cat_id );
    foreach( $childs as $child ) {
    	$ids[] = $child->term_id;
    }
    $html = wp_list_categories( array(
    	'title_li' => '',
    	'hide_empty' => 0,
    	'echo' => 1,
    	'show_option_none' => '',
    	'include' => implode( ',', $ids )
    ) );

    That's some pretty nasty stuff.

Topic Closed

This topic has been closed to new replies.

About this Topic