最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

categories - Display menu in category and sub category

programmeradmin1浏览0评论

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?

发布评论

评论列表(0)

  1. 暂无评论