WordPress.org

Ready to get started?Download WordPress

Forums

Hightlighting current link in menus - with categories and pages (2 posts)

  1. totallyrich
    Member
    Posted 5 years ago #

    Hello!

    I'm trying to get this menu to work on my custom theme:

    http://www.totallyrich.com

    The menu links are hardcoded into the header.php template. As you can see I use 'Home' one page and four categories. Here's the code I have tried to use:

    <ul>
    				  <?php if(is_home() &amp;&amp; !is_paged()){ ?>
    				   <!-- li>
    				    <a class="current"href="<?php echo get_settings('home'); ?>" title="You are Home">Blog Navigation</a>
    				   </li -->
    				 <?php } else { ?>
    				  <li>
    				   <a href="<?php echo get_settings('home'); ?>" title="Click for Home">Home</a>
    				  </li>
    				 <?php } ?>
    
    					<li>
    				            <a <?php
    							if (is_category('Photography') || in_category('27') &amp;&amp; !is_single())
    			                {
    			                echo " class=\"current\"";
    			                }?> href="<?php bloginfo('url') ?>/category/photography">Photography</a>
    				        </li>
    
    					<li>
    				            <a <?php
    							if (is_category('The Interweb') || in_category('25') &amp;&amp; !is_single())
    			                {
    			                echo " class=\"current\"";
    			                }?> href="<?php bloginfo('url') ?>/category/the-interweb">The Interweb</a>
    				        </li>
    
    					 <li>
    				            <a <?php
    							if (is_category('Motorsport') || in_category('24') &amp;&amp; !is_single())
    			                {
    			                echo " class=\"current\"";
    			                }?> href="<?php bloginfo('url') ?>/category/motorsport">Motorsport</a>
    				        </li>
    
    			        <li>
    			                <a <?php
    					        if (is_category('Everything Else') || in_category('28') &amp;&amp; !is_single())
    			                {
    			                echo " class=\"current\"";
    			                }?> href="<?php bloginfo('url') ?>/category/everything-else">Everything Else</a>
    			        </li>
    
    			        <li>
    			                <a <?php
    					        if (is_page('Contact'))
    			                {
    			                echo " class=\"current\"";
    			                }?> href="<?php bloginfo('url') ?>/contact">Contact</a>
    			        </li>
    			</ul>

    Issue 1:
    When on the homepage the 'Motorsport' link is highlighted.

    Issue 2:
    When on the contact page the 'Everything Else' link is highlighted.

    Issue 3:
    If you click though to a single post the menu loses it's highlighting.

    Has anyone tried something like this before? or do you have any ideas how I can make this work???

    Looking forward to hear your response...

    Cheers,
    Rich

  2. stvwlf
    Member
    Posted 5 years ago #

    hi

    confusing as it is, to indicate the homepage use is_front_page() - is_home() refers to the posts page

    most of your IF statements include "and not is_single()" - that explains why the menu is not higlighted when on a single page.

    I can't see offhand why Everything Else is lit up, but it will prove to be something similar - some logic you are not looking at it causing its IF statement to evaluate as true. You have 3 conditions in that statement - take them out one at a time and find the one that is evaluating to true

    BTW, its a good idea for maintaining sanity when mixing OR's and AND's in IF statements to put all the OR's together in one pair of parentheses, followed by the AND's - helps keep straight what is going on - if one OR evaluates to true, the whole parentheses is true, and gets AND'ed with the ANDs

Topic Closed

This topic has been closed to new replies.

About this Topic