WordPress.org

Ready to get started?Download WordPress

Forums

How to higlight navigation menu current item on sub-categories and posts (7 posts)

  1. TheMadcore
    Member
    Posted 3 years ago #

    Hi folks.

    I´ve created a custom navigation menu, but it only add the highlight class "current menu item" to the top categories and top pages. When a sub-category, a post, or a sub-page is viewed, none of the menu items are highlighted. I want to fix that.

    The idea is: The menu have a "Blog category", and is highlighted when that category is viewed. If a subcategory of "blog" selected, for example "personal", is selected, I want the "blog" item highlighted. The same if some post asociated with the "blog" category or one of his sub-categories is viewed.

    I have a some custom functions made by myself to do it on WP versions prior to 3.0, but I want to use custom navigation menus now. So if someone knows how to do that with custom navigation menu, I will thanks him with all of my soul.

  2. funkyole
    Member
    Posted 3 years ago #

    TheMadcore,

    I'm looking for something similar and I'm wondering if you have found a solution.

    I'm making pages based on categories as menu items and each pege has its own template. And when I select a page in the menu the current item state is ok. But when I'm selecting a post within that category the current item status disappears.

    Maybe you can help me with your previous solution?

  3. levenen
    Member
    Posted 3 years ago #

    Me too . . . if I find this answered somewhere, I'll post the answer here.

  4. funkyole
    Member
    Posted 3 years ago #

    I solved it with this:

    <li class="<?php if (is_page(pagename)) { echo "current_page_item"; } ; if (in_category('categoryname')) { echo "current_page_item"; }?>"><a href="3">menu</a>

    take a look and let me know if it is clear :)

  5. ucarmetin
    Member
    Posted 3 years ago #

    Hi!

    @funkyole's example inspired me and I created my own custom menu with custom highlighting of menu items based on categories. However, there is a strange highlighting error. While the front page is viewed, the last menu item Spel ( "Game" in english ) is highlighted as well. Here's the code I'm using for highlighting menu items.

    <?php if(in_category('spel')) {?>
                	<li><a href="<?php bloginfo('url'); ?>/category/spel/" class="highlight-spel">Spel</a></li>
                <?php } else {?>
    				<li><a href="<?php bloginfo('url'); ?>/category/spel/">Spel</a></li>
                <?php }?>

    Any idea why I'm getting this strange error?

    Thanks.

  6. Ingenius Dastard
    Member
    Posted 3 years ago #

    Is there anyone from WordPress team looking into this? This is a very lacking feature of the WordPress navigation component.

  7. glebis
    Member
    Posted 2 years ago #

    If you want to use WordPress' built-in menu, you probably have to play around wp_get_nav_menu_items (introduced in WP 3.0) to add extra classes to menu items.

    I remember using xml parsers and custom walkers for the very same purpose, things have got just a little bit easier since that time.

Topic Closed

This topic has been closed to new replies.

About this Topic