SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jun 2006
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    detecting menu variables through URLs

    hi everyone,

    so at the end of a project a client has decided they want to have every like in a navigation menu be highlighted when they are on that exact page.

    aside from creating one navigation menu for every page, or opening up every single page and providing a new variable that will trigger an "active" class in the side nav, is there a way I could just write a big if/else statement and include it in each ul/li include (there are about 5 or 6 navigation includes used), and determine it based on the URL?

    for example, a sample URL may be this:

    mysite.com/index.php?content=about_directions

    what would be the PHP way for me to write the following English logic?
    PHP Code:
    <ul>
    <
    li>contact</li>
    <
    li  if URL says Directions is trueadd class:"active">Directions</a>
    <
    li>home</li>
    </
    ul
    so that directions would have a different appearance than contact or home?

    any ideas? should i rephrase my question?

    thanks in advance!!!!

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You could do this:
    PHP Code:
    $what $_GET['content'];
    $items = array(
      
    'index' => 'Home',
      
    'contact' => 'Contact us',
      
    'about_directions' => 'Directions'
    );
    if (!
    $what || !in_array($what$items)) {$what 'index';}
    foreach (
    $items as $key => $value) {
      echo 
    '<li';
      echo 
    $key === $what ' class="active"' '';
      echo 
    ">$value</li>";



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •