• Resolved bmg1227

    (@bmg1227)


    Ok, now onto the next trick. I want to highlight the current category link in the navbar when viewing a post within that category, not just when the category “archive” page is being viewed.

    Here’s the current code I am using to pull category links in the navbar:

    <?php wp_list_categories(‘sort_column=name&title_li=’); ?>

Viewing 2 replies - 16 through 17 (of 17 total)
  • joandiego – wonderful! Thanks so much for that.

    The only problem I have now is the fact that the page_parent of a category page is the default posts page.

    In my stylesheet I have:

    #nav ul li.current_page_item a, #nav ul li.current_page_parent a, #nav ul li.current-cat a {
    		color: #AA0000;
    	}

    The parent menu item of a child page is still highlighted when on that child page, and the menu item of a category is highlighted when on a category page.

    But because, when on a category page, the default posts page is marked with ‘current_page_parent’, it means the default posts page menu item is highlighted AS WELL AS the category, when on a category page.

    Is there any way round this? So that I can still highlight parent menu items to a depth of 2 on both static pages and category pages, without the posts page highlighting when on a category page?

    joandiego,

    Your code works great, but it seems to work only for one level of child nesting. Do you think you could get it to work for three or more, or an infinite amount of child nesting?

    Thanks!

Viewing 2 replies - 16 through 17 (of 17 total)
  • The topic ‘Highlight Current Category in Navbar on Single Page’ is closed to new replies.