• I am using the wp_nav_menu with a custom ‘fallback_cb’ for category menu and sub menu which is great to just two levels.

    <!--
    main category menu
    -->
    <?php wp_nav_menu( array( 'container_class' => '','theme_location' => 'none','fallback_cb'=>'digimag_top_categories') ); ?>
    
    <?php wp_nav_menu( array( 'container_class' => '','theme_location' => 'none','fallback_cb'=>'digimag_child_categories') ); ?>
    <!--
    Sub Category Menu if any exist
    -->

    For a magazine / news theme I need three levels like Sports > Football > “Premier League”

    So I need the parent “Football” and the ancestor “Sports” both highlighted in the main category menu and the sub-category menus for “Premier League” or it’s children.

    Anyone know the code or a tutorail to add a category ancestor class to wp_nav_menu?

    David ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • Oh – this drives me nuts too. The lack of an ancestor class for categories is a real oversight, in my opinion. Not sure if this is exactly what you want but it might get you started: https://pastebin.com/airB2wE7

    Thread Starter Digital Raindrops

    (@adeptris)

    Hi Esmi,
    Many thanks for sharing, that example has done the ‘logic’ trick, I could not quite work out how many levels the example covered.

    I might be wrong but it looks to only updates the class of the top level category, and we could have a multi level tree.

    I worked code from the current category up through the levels, using the append code in the example.
    https://pastebin.com/Dygt3GiD

    Here is a multi-level (5) test “Cat A” to “Cat E”, ancestor, ancestor, ancestor, parent and active.

    I have only updated the main category menu not the sub-menu yet!

    Thanks

    David

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘current-cat-ancestor class?’ is closed to new replies.