Forums

in_category problems on homepage (2 posts)

  1. danbranigan
    Member
    Posted 3 years ago #

    Hi,

    I'm trying to get my main menu tabs to hilight depending upon which page, category, post etc is displaying.

    I've got it working fine picking up pages, and categories but it's the post level that is proving to be a bit tricky. When I use in_category(), the home tab gets hilighted also - it seems that in_category() is returning as TRUE for this page?

    I've attached an exmaple of my code below:

    <li <?php //About Us tab
    		if ( $post->post_parent == '2' || is_category(array(79,80)) || in_category(array(79,80)) ) {
    		?>class="current"<?php }?>><a href="/about/accountants-for-life/">About Us</a></li>

    Also do i REALLY need the is_category condition - I tired it with just the in_category condition and it seemed to work OK except for the homepage issue.

    I'd appreciate any help. Thanks.

  2. Dagon Design
    Member
    Posted 3 years ago #

    For your home tab, just use the is_home() function. Assuming by 'home' you mean your main index file, or you can use is_front_page()

    Otherwise, for static pages, you can use one of these methods:
    is_page('123') (where 123 is the page ID)
    is_page('The Page Title')

    They will return TRUE if that particular page is being viewed.

    There are many other conditionals you can use:

    http://codex.wordpress.org/Conditional_Tags

    As for sub-pages, if they are only one level deep you can do this:

    if ( is_page('123') || $post->post_parent == '123' ) {

    That will trigger if you are viewing the page with the ID 123, or if you are viewing one of its sub-pages.

    Hope that helps!

Topic Closed

This topic has been closed to new replies.

About this Topic