SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    May 2005
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Navigation Script Problems

    I'm using Matt's navigation script but am obviously doing something wrong. Can someone please take a look and let me know what the problem is with my code?

    Code:
    <?php
    $menu = <<<MENU
      <div id="headstuff"> 
        <div id="header"><h1><a href="http://www.mysite.com"><img src="images/logo.gif" height="48" width="280" alt="mysite.com" border="0" /></a><img src="images/slogans/kip.gif" height="15" width="99" alt="pharmaceutical sales megasite" /></h1></div>
        <ul id="nav">
          <li class="off"><a href="/"><img src="images/mainpage.gif" height="5" width="57" /></a></li>
          <li class="off"><a href="/board/"><img src="images/messageboards.gif" height="5" width="94" /></a></li>
          <li class="off"><a href="/detailbag/"><img src="images/detailbag.gif" height="5" width="61" /></a></li>
          <li class="off"><a href="/links/"><img src="images/links.gif" height="5" width="29" /></a></li>
          <li class="off"><a href="/store/"><img src="images/store.gif" height="5" width="66" /></a></li>
          <li id="last" class="off"><a href="/login/"><img src="images/login.gif" height="5" width="29" /></a></li>
        </ul>
      </div>
    MENU;
    
    $lines = split("\n", $menu);
    foreach ($lines as $line) {
        $current = false;
        preg_match('/href="([^"]+)"/', $line, $url);
        if (substr($_SERVER["REQUEST_URI"], 0, 5) == substr($url[1], 0, 5)) {
            $line = str_replace('<a h', '<a id="current" h', $line);
    		//$line = str_replace('class="off"', 'class="on"', $line);
            }
        echo $line."\n";
    }
    ?>
    You can find the original script from Matt's site here.

    Thanks in advance!

  2. #2
    SitePoint Member
    Join Date
    May 2005
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    **bump**

  3. #3
    SitePoint Addict Shockt's Avatar
    Join Date
    Jan 2005
    Location
    California
    Posts
    360
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For kicks, give this a shot:

    Code:
    <?php
    $menu = "  <div id="headstuff"> 
        <div id="header"><h1><a href="http://www.mysite.com"><img src="images/logo.gif" height="48" width="280" alt="mysite.com" border="0" /></a><img src="images/slogans/kip.gif" height="15" width="99" alt="pharmaceutical sales megasite" /></h1></div>
        <ul id="nav">
          <li class="off"><a href="/"><img src="images/mainpage.gif" height="5" width="57" /></a></li>
          <li class="off"><a href="/board/"><img src="images/messageboards.gif" height="5" width="94" /></a></li>
          <li class="off"><a href="/detailbag/"><img src="images/detailbag.gif" height="5" width="61" /></a></li>
          <li class="off"><a href="/links/"><img src="images/links.gif" height="5" width="29" /></a></li>
          <li class="off"><a href="/store/"><img src="images/store.gif" height="5" width="66" /></a></li>
          <li id="last" class="off"><a href="/login/"><img src="images/login.gif" height="5" width="29" /></a></li>
        </ul>
      </div>";
    
    $lines = split("\n", $menu);
    foreach ($lines as $line) {
        $current = false;
        preg_match('/href="([^"]+)"/', $line, $url);
        if (substr($_SERVER["REQUEST_URI"], 0, 5) == substr($url[1], 0, 5)) {
            $line = str_replace('<a h', '<a id="current" h', $line);
    		//$line = str_replace('class="off"', 'class="on"', $line);
            }
        echo $line."\n";
    }
    ?>
    If that doesnt work, I have no idea. First of all, I have never seen this <<<MENU functionality before. Normally when setting a string to a variable, it must be in quotes so the lack of quotes got me confused. Secondly, all this script seems to do is output the exact code you have typed except adding an id="current" attribute to each <a> tag.

  4. #4
    SitePoint Member
    Join Date
    May 2005
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks shock-
    the script actually adds a "current tag" to the links that are the same as the current directory.

    thanks again. ill let you know.
    ryan

  5. #5
    SitePoint Member
    Join Date
    May 2005
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no such luck.

    anyone else?

  6. #6
    get into it! bigduke's Avatar
    Join Date
    May 2004
    Location
    Australia
    Posts
    847
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    replace that last bit of loop with
    PHP Code:
    $currentValue substr($_SERVER[”REQUEST_URI”], 0strpos($_SERVER[”REQUEST_URI”],/1) )./” ;
    echo 
    $menuCode str_replace(”href=\”$currentValue\", “id=\”current\” href=\”$currentValue\”"$menu); 


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
  •