dynamic php menu with hidden sub-categories only showing when the category name is clicked

This is for a wordpress store and I want to show the categories names automatically, but with the sub-categories hidden, the code below works perfectly with the hover effect, now I wish to have the click effect instead. The $cats variable is to use the get_terms() function, but for here to work everywhere I had included a few categories, the categories only go so far as the “third generation”.

WordPress hide post from custom post-type on a single page

Initial situation custom post-type (projects)[projects.php] <?php namespace main_themeextposttypesprojects; function post_type() { $labels = [ 'name' => _x( 'Projects', 'Post Type General Name', 'main_theme' ), 'singular_name' => _x( 'Project', 'Post Type Singular Name', 'main_theme' ), 'menu_name' => __( 'Projects', 'main_theme' ), 'name_admin_bar' => __( 'Projects', 'main_theme' ), 'all_items' => __( 'Alle Projects', 'main_theme' ), 'add_new_item' => … Read more