Wordpress Navigation Issue

Discussion in 'PHP' started by Forest_Parks, Dec 3, 2008.

  1. #1
    HI Guys,

    I am just working on a few tweaks to a theme and have hit a small problem with the navigation.

    As you can see here: http:guitarheroplus.com when home is selected the tab in the navigation will not display as blue (current) tab whereas the others will.

    My code in header php to call the navigation in is:

    <div id="navi">
    <ul id="nav">

    <li class="page_item">
    <a href="<?php echo get_settings('home'); ?>/" title="Home">Home</a>
    </li>
    <?php $pages = wp_list_pages('sort_column=menu_order&depth=1&title_li=&echo=0');
    print_r($pages);
    ?>
    </ul>
    </div>


    And the style is:

    #navi {
    position:relative;
    height: 25px;
    width: 901px;
    margin: 0px auto;
    top: 60px;
    text-align: center;
    line-height: normal;
    }
    #nav {
    list-style: none;
    margin: 0 1px;
    padding: 0px;
    float: left;
    clear:both;
    }
    #nav li {
    float: left;
    height: 25px;
    background: url(images/navtabr.gif) top right no-repeat;
    margin: 0 1px;
    white-space: nowrap;
    }
    #nav .page_item a{
    color: #white;
    display: block;
    background: url(images/navtabl.gif) top left no-repeat;
    text-decoration: none;
    padding: 0px 10px 0px 10px;

    line-height: 25px;
    }

    #nav li:hover {
    background-position: 100% -36px;
    }



    #nav .page_item a:hover {
    background-position: 0px -36px;
    border: none;
    }

    #nav li.current_page_item {
    color: white;
    text-decoration: none;
    background: url(images/navtabactiver.gif) top right no-repeat;
    }
    #nav .current_page_item a, #nav .current_page_item a:visited{
    color: white;
    text-decoration: none;
    background: url(images/navtabactivel.gif) top left no-repeat;
    }


    If anyone has any idea how I would get the Home tab to display in blue when it is the current item I would appreciate the help a lot.

    Cheers,

    Forest.
     
    Forest_Parks, Dec 3, 2008 IP
  2. misbah

    misbah Active Member

    Messages:
    265
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    68
    #2
    replace this line
    <li class="page_item">
    PHP:
    with this
    <li class="page_item <?php if ( is_home()) echo 'current_page_item'; ?>">
    PHP:
     
    misbah, Dec 4, 2008 IP
  3. Forest_Parks

    Forest_Parks Peon

    Messages:
    106
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks so much that solved the problem... I don't understand why but it did :)
     
    Forest_Parks, Dec 6, 2008 IP
  4. najafali

    najafali Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Nice bit of code there. I think is_home() checks if this current page is the home page. If that evaluates to true it adds the 'current_page_item' class to your link.
     
    najafali, Dec 7, 2008 IP