A little navigation bar that I made

  • IcyDragoon
  • Student
  • Student
  • IcyDragoon
  • Posts: 65

Post 3+ Months Ago

Code: [ Select ]
<?php
$locArray = array(
    "" => "Home Page",
    "img" => "Image Gallery",
    "dl" => "Downloads",
    "naruto" => "Naruto Shippuden",
    "bbs" => "Community",
    "contact" => "Contact",
    "about" => "About Us"
);

function location(){ //put this in global file
    global $siteURL, $locArray, $title; //I have title as a global, you can passed it as an argument
    $temp = explode("/", $_SERVER['REQUEST_URI']);
    $i = 0;
    $theURL = $siteURL;
    $retval = "<a href=\"".$theURL."\" title=\"".$locArray[$temp[$i]]."\" target=\"_self\"> ".$locArray[$temp[$i]]."</a>";
    for($i = 1; $i < sizeof($temp)-1; ++$i){
        $theURL .= "/" . $temp[$i];
        $retval .= " -> <a href=\"".$theURL."\" title=\"".$locArray[$temp[$i]]."\" target=\"_self\"> ".$locArray[$temp[$i]]."</a>";
    }
    $retval .= " -> $title"; //title = the title of the current page
    return $retval;
}
?>
  1. <?php
  2. $locArray = array(
  3.     "" => "Home Page",
  4.     "img" => "Image Gallery",
  5.     "dl" => "Downloads",
  6.     "naruto" => "Naruto Shippuden",
  7.     "bbs" => "Community",
  8.     "contact" => "Contact",
  9.     "about" => "About Us"
  10. );
  11. function location(){ //put this in global file
  12.     global $siteURL, $locArray, $title; //I have title as a global, you can passed it as an argument
  13.     $temp = explode("/", $_SERVER['REQUEST_URI']);
  14.     $i = 0;
  15.     $theURL = $siteURL;
  16.     $retval = "<a href=\"".$theURL."\" title=\"".$locArray[$temp[$i]]."\" target=\"_self\"> ".$locArray[$temp[$i]]."</a>";
  17.     for($i = 1; $i < sizeof($temp)-1; ++$i){
  18.         $theURL .= "/" . $temp[$i];
  19.         $retval .= " -> <a href=\"".$theURL."\" title=\"".$locArray[$temp[$i]]."\" target=\"_self\"> ".$locArray[$temp[$i]]."</a>";
  20.     }
  21.     $retval .= " -> $title"; //title = the title of the current page
  22.     return $retval;
  23. }
  24. ?>


What this does is the following:
Lets say I have a website at http://www.domain.com, so I set the $siteURL to that URL.
Now, if I call this function from http://www.domain.com/img/naruto/,
and the page has a title called: "Naruto: Shippuden High Quality Wallpapers".
This function will return the following result:

Code: [ Select ]
<a href="http://www.domain.com/" title="Home Page" target="_self">Home Page</a>->
<a href="http://www.domain.com/img/" title="Image Gallery" target="_self">Image Gallery</a>->
<a href="http://www.domain.com/img/naruto/" title="Naruto Shippuden" target="_self">Naruto Shippuden</a>->
Naruto: Shippuden High Quality Wallpapers
  1. <a href="http://www.domain.com/" title="Home Page" target="_self">Home Page</a>->
  2. <a href="http://www.domain.com/img/" title="Image Gallery" target="_self">Image Gallery</a>->
  3. <a href="http://www.domain.com/img/naruto/" title="Naruto Shippuden" target="_self">Naruto Shippuden</a>->
  4. Naruto: Shippuden High Quality Wallpapers

NOTE: I put each anchor in a new line so you can have a clear look; the code produced, doesn't do the linebreak.

I would like some experts to have a clear look at my code and comment on it, is it good? is it bad? should I improve it? and etc.



PS: feel free to use the code if you like it ^^.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

Post Information

  • Total Posts in this topic: 1 post
  • Users browsing this forum: No registered users and 103 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.