Jump to content

[SOLVED] Breadrumbs using rewritten urls


AdRock

Recommended Posts

I have a breadcrumb script which someone else wrote and it works perfectly until i want to go back a directory

 

If i have a url like contact-us, i get a breadcrumb like home > contact-us

 

but if i have a rewritten url like news.php?page=num=3 and rewrite it to home > news > 3 and i click on news, it can't find the page becuase it's trying to find news/

 

Is there anything in here that could be causing it or do i have to look at my rewrite rules?

 

function breadcrumb(
            $home = 'Home', // Name of root link
            $division = ' / ', // Divider between links
            $hidextra = true, // Toggle hide/show get data and fragment in text
            $index = false,  // Toggle show/hide link to directory if it does not contain a file
            $indexname = 'index.php' // The definition of the file the directory must contain
) {

$breadcrumb="";

    // Requested addons...
    $extension = '.php'; // Extension to cut off the end of the TEXT links
    $ifIndex = 'index.php'; // Filename of index/default/home files to not display
    // End requested addons

    $whole = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    $parts = explode('/', $whole);
    $parts[0] = 'http://'.$parts[0];

$array = array('-', '%20');

    $breadcrumb .=  "<a href=\"{$parts[0]}\">{$home}</a>{$division}";
    $k = 1;
    for ($i=1;$i < sizeof($parts);$i++) {
        $uri = '/';
        while ($k <= $i) {
                $uri .= $parts[$k];
                if ($k != (sizeof($parts)-1)) $uri .= '/';
                $k++;
         }
          if (($index && is_dir($_SERVER['DOCUMENT_ROOT'].$uri) && is_file($_SERVER['DOCUMENT_ROOT'].$uri.$indexname) 
        || !$index 
        || !is_dir($_SERVER['DOCUMENT_ROOT'].$uri)) && $parts[$i] != $ifIndex) {
            $breadcrumb .= "<a href=\"$uri\">";
            if ($hidextra) {
                $breadcrumb .= rtrim(preg_replace("/\?.*$/", '', ucwords(str_replace($array," ",$parts[$i]))), $extension);
            }
            else {
                $breadcrumb .= rtrim(ucwords($parts[$i]), $extension);
            }
            $breadcrumb .= '</a>';
        }
        else {
            $breadcrumb .= ucwords(str_replace($array," ",$parts[$i]));
        }

          if (isset($parts[($i+1)])) {
            $breadcrumb .= $division;
        }
          $k = 1;
    }
    return $breadcrumb;
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.