WordPress.org

Ready to get started?Download WordPress

Forums

Dynamically highlight menu when viewing posts that belong to a category (5 posts)

  1. Shaun Brown
    Member
    Posted 3 years ago #

    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>
  2. Shaun Brown
    Member
    Posted 3 years ago #

    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.

  3. Shaun Brown
    Member
    Posted 3 years ago #

    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?....

  4. Shaun Brown
    Member
    Posted 3 years ago #

    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?

  5. Shaun Brown
    Member
    Posted 3 years ago #

    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?

Topic Closed

This topic has been closed to new replies.

About this Topic