• Greetings,
    Ive created a hard-coded navigation menu with an image sprite that utilizes <?php if ( is_page('')) { echo ' class="" '; } ?> to dynamically highlight each page, however I would like to keep the associated page highlighted once the visitor clicks on a post and views it from the single template (I have multiple single page templates)….right now this does not work, but I dont know how to make it work.

    Here is my current nav markup:

    <ul id="nav">
    	<li>
    		<a href="/" id="logo"></a>
    	</li>
    	<li>
    		<a href="/" id="home" <?php if ( is_page('events')) { echo ' class="home_highlight" '; } ?>></a>
    	</li>
    	<li>
    		<a href="#" id="artists" <?php if ( is_page('artists')) { echo ' class="artists_highlight" '; } ?>></a>
    	</li>
    	<li>
    		<a href="/media" id="media" <?php if ( is_page('media')) { echo ' class="media_highlight" '; } ?>></a>
    	</li>
    	<li>
    		<a href="/blog" id="blog" <?php if ( is_home('blog')) { echo ' class="blog_highlight"'; } ?>></a>
    	</li>
    	<li>
    		<a href="#" id="store" <?php if ( is_page('store')) { echo ' class="store_highlight" '; } ?>></a>
    	</li>
    	<li>
    		<a href="#" id="contact" <?php if ( is_page('contact')) { echo ' class="contact_highlight" '; } ?>></a>
    	</li>
    </ul>

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Shaun Brown

    (@steezo)

    I think I figured it out….I was previously trying is_category('events') —- I changed that to in_category('events') instead and it worked perfect for the way I coded my site.

    Thread Starter Shaun Brown

    (@steezo)

    It just dawned on me though that I’m not exactly sure if I will need a different conditional for something like child pages of the static pages?….

    Thread Starter Shaun Brown

    (@steezo)

    In case anybodies actually reading this…
    I ran into a small problem with in_category()….as soon as I posted something in both my “blog” & “media” categories which both have their own respective pages both links became highlighted in my navigation simultaneously 🙁 Not sure how to remedy that so I removed in_category() all together. Anybody have experience dealing with this sort of thing on a hard-coded image sprite menu?

    Thread Starter Shaun Brown

    (@steezo)

    Sooo….even stranger, in_category() seems to work just fine when testing with MAMP, however as soon as its server side and uploaded to the real site it still highlights both pages when viewing the Blog.

    Just need a push in the right direction, anybody?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Dynamically highlight menu when viewing posts that belong to a category’ is closed to new replies.