Display menu in category and sub category

I need to show menu with all subcategories for specific category (and sub category).

When code looks like this:

<?php if (is_category(‘news’)) : ?>
<?php wp_nav_menu( array( ‘theme_location’ => ‘news-menu’ ) ); ?>
<?php endif; ?>

<?php if (is_category(‘articles’)) : ?>
<?php wp_nav_menu( array( ‘theme_location’ => ‘articles-menu’ ) ); ?>
<?php endif; ?>

Menu is displayed correctly on main category page – in sidebar is shown full list of subcategories. When i am going to subcategory, for example news/sales – menu in sidebar is not appearing. To fix that i changed code like this:

<?php if (is_category(‘news’) || in_category(‘news’)) : ?>
<?php wp_nav_menu( array( ‘theme_location’ => ‘news-menu’ ) ); ?>
<?php endif; ?>

<?php if (is_category(‘articles’) || in_category(‘articles’)) : ?>
<?php wp_nav_menu( array( ‘theme_location’ => ‘articles-menu’ ) ); ?>
<?php endif; ?>

After that when i am in page of subcategory (let’s say news/sales) menu is shown correctly, but in main category news i see both menus for news AND articles.

Any ideas how to make it work? That both main categories and their subpages will show only their own menus, not both menus which re avaliable?

Read more here:: Display menu in category and sub category

Leave a Reply

Your email address will not be published. Required fields are marked *