roryashfordbentley / Wordpress-Bem-Menu

Better menu implementation for Wordpress using BEM syntax
139 stars 23 forks source link

Custom post type archives with categories doesnt have an active link on parent #12

Closed roryashfordbentley closed 8 years ago

roryashfordbentley commented 8 years ago

This behaviour is the same in WP core I believe.

If you have a CPT with categories taxonomy. If you are on the archive page the active category is marked as --parent but if you visit the 'single.php' template it is not.

roryashfordbentley commented 8 years ago

This is more complex than I thought as a post can have multiple taxonomies. If anyone reading this has any ideas for how we can gracefully add this functionality I'm all ears.

roryashfordbentley commented 8 years ago
        /**
         * 1. Get current post post_type
         * 2. Get all taxonomies from post type
         * 3. Get all terms for each post type and add to single dimensional array.
         * 4. Add array items to menu items and parent as appropriate! 
         */

        $current_page_taxonomies = get_object_taxonomies( get_post_type($post->ID) );
        print_r($current_page_taxonomies);

        print_r($current_taxs);

        //current menu item taxonomy
        $menu_item_taxonomy = $item->object;

        if( has_term( '', $menu_item_taxonomy ) ) {

            echo '<strong>' . $menu_item_taxonomy. '</strong>';
            echo "<br>";

            $menu_item_terms = get_terms($menu_item_taxonomy);

            /* create array of terms associated with each menu item */
            foreach($menu_item_terms as $term){
                $menu_item_term_arr[] = $term->slug;
            }

            print_r($menu_item_term_arr);

        }

A little brain-dump of the components that will go into the eventual solution.

roryashfordbentley commented 8 years ago

Closing this for now.