Forums

Current_page_item highlights two menu items at same time (6 posts)

  1. demonboy
    Member
    Posted 1 year ago #

    Good afternoon,

    Currently I am using this code for my menu:

    <li<?php if ( is_home() ) { echo ' class="current_page_item"'; } ?>><a href="<?php echo get_option('home'); ?>"><span>Home</span></a></li>
    	<li<?php if ( is_page('about') || is_page('94') || is_page('83') || is_page('79') || is_page('73') || is_page('3339') || is_page('77') || is_page('20228') || is_page('20232') || is_page('75') || is_page('contact')) { echo ' class="current_page_item"'; } ?>><a href="http://www.followtheboat.com/about">About</a></li>
        <li<?php if ( is_page('places-2')) { echo ' class="current_page_item"'; } ?>><a href="http://www.followtheboat.com/places-2">Places</a></li>
    	<li<?php if ( is_page('photography') || in_category('447')) { echo ' class="current_page_item"'; } ?>><a href="http://www.followtheboat.com/photography">Photography</a></li>
    	<li<?php if ( is_page('ftb-podcasts') || in_category('601')) { echo ' class="current_page_item"'; } ?>><a href="http://www.followtheboat.com/ftb-podcasts">Podcasts</a></li>

    I realise that the About item could probably be an array but that's not my issue. My problem is this:

    When I create a new blog entry in the category 'podcast', the homepage highlights both the menu item 'Home' and menu item 'Podcast'. When on the homepage I don't want it to highlight 'Podcast'. Could anyone tell me what I am doing wrong? Shouldn't the is_home() part prevent any other menu item from being highlighted or do I have to actually declare what is_home is?

    Thanks in advance.

  2. jevets
    Member
    Posted 1 year ago #

    Try it with is_front_page() instead of is_home()

    http://codex.wordpress.org/Function_Reference/is_front_page

  3. demonboy
    Member
    Posted 1 year ago #

    Hi. Tried that to no avail.

  4. jevets
    Member
    Posted 1 year ago #

    The problem is that your post is in_category('601'). So your condition of is_page('ftb-podcasts') || in_category('601') returns true on the home page.

    You could try something like this:
    if (is_page('ftb-podcasts') || (is_single() && in_category(601)))

  5. demonboy
    Member
    Posted 1 year ago #

    Hi jevets,

    That appears to have done the trick! Thanks very much for your time, I appreciate it.

    Cheers.

  6. demonboy
    Member
    Posted 1 year ago #

    EEEEK! Scrap that last comment! That very definitely did not work! I must have had my website cached when I tried your solution, jevets. All that happened was that it wrote out the code for the page instead of actually displaying it.

    Any other ideas?

Topic Closed

This topic has been closed to new replies.

About this Topic