Support » Plugins » Settingg active class for home, pages, and categories problem?

  • OK, I’m puzzled. I setup active classes using PHP to check if I’m on a specific page, category or sub cat. Everything works as expected accept when on the home page I’m getting an active class on the home page AND page 2?

    <ul>
        <li <?php if(is_home()){?> class="active"<?php }?> >
        	<a href="/" >Home</a>
        </li>
        <li <?php if (is_page('1') || in_category('1') || post_is_in_descendant_category( 1 )) { ?> class="active" <?php }?> >
        	<a href="/page1">Page 1</a>
        </li>
        <li <?php if (is_page('2') || in_category('2') || post_is_in_descendant_category( 2 )) { ?> class="active" <?php }?> >
        	<a href="/page2">Page2</a>
        </li>
        <li <?php if (is_page('3')){?> class="active" <?php }?> >
        	<a href="/page3">page3</a>
        </li>
    </ul>

    For some reason post_is_in_descendant_category( 2 ) is true when im on the home page?

    I have no idea, any help would be awesome!

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

    (@jwack)

    Here is the funtion for post_is_in_descendant_category…

    function post_is_in_descendant_category( $cats, $_post = null )
    {
    	foreach ( (array) $cats as $cat ) {
    		// get_term_children() accepts integer ID only
    		$descendants = get_term_children( (int) $cat, 'category');
    		if ( $descendants && in_category( $descendants, $_post ) )
    			return true;
    	}
    	return false;
    }

    Thread Starter jwack

    (@jwack)

    anyone have any ideas why post_is_in_descendant_category( 2 ) would be true on the home page, causing 2 active links?

    Thread Starter jwack

    (@jwack)

    hmmm

    Thread Starter jwack

    (@jwack)

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Settingg active class for home, pages, and categories problem?’ is closed to new replies.