目次・あらすじ

            $make_hierarchical_categories = function ( $array ) use ( &$make_hierarchical_categories ) {
                foreach ( $array as $item ) {
                    $children = get_categories( array( 'parent' => $item->cat_ID ) );
                    if ( $children ) {
                        $item->child = $children;
                        $make_hierarchical_categories( $children );
                    }
                }
                return $array;
            };
    
            $categories = $make_hierarchical_categories( get_categories( array( 'parent' => 0 ) ) );