下面我用這個代碼在我的網站來處理麪包屑, 這個代碼,我得到的所有時間的問題在同一層次,而不是真正的..麪包屑不工作
例如:網址是hxxp://fakesite.com/A/B/C/d
它將打印:
首頁»一個»B»ç»d(它的好,但檢查下面的鏈接)
但聯繫總是會在主頁上一層:
hxxp://fakesite.com/-->Home
hxxp://fakesite.com/A-->A
hxxp://fakesite.com/B-->B
hxxp://fakesite.com/C-->C
代替
hxxp://fakesite.com/-->Home
hxxp://fakesite.com/A-->A
hxxp://fakesite.com/A/B-->B
hxxp://fakesite.com/A/B/C-->C
我怎樣才能解決這個問題有正確的層次
感謝您的幫助!
<?php
// This function will take $_SERVER['REQUEST_URI'] and build a breadcrumb based on the user's current path
function breadcrumbs($separator = ' » ', $home = 'Home') {
// This gets the REQUEST_URI (/path/to/file.php), splits the string (using '/') into an array, and then filters out any empty values
$path = array_filter(explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)));
// This will build our "base URL" ... Also accounts for HTTPS :)
$base = ($_SERVER['HTTPS'] ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/';
// Initialize a temporary array with our breadcrumbs. (starting with our home page, which I'm assuming will be the base URL)
$breadcrumbs = Array("<a href=\"$base\">$home</a>");
$last = end(array_keys($path));
// Find out the index for the last value in our path array
$last = end(array_keys($path));
// Build the rest of the breadcrumbs
foreach ($path AS $x => $crumb) {
// Our "title" is the text that will be displayed (strip out .php and turn '_' into a space)
$title = ucwords(str_replace(Array('.php', '_'), Array('', ' '), $crumb));
// If we are not on the last index, then display an <a> tag
if ($x != $last)
$breadcrumbs[] = "<a href=\"$base$crumb\">$title</a>";
// Otherwise, just display the title (minus)
else
$breadcrumbs[] = $title;
}
// Build our temporary array (pieces of bread) into one big string :)
return implode($separator, $breadcrumbs);
}
?>
<p><?= breadcrumbs() ?></p>
感謝您的幫助!
你的意思是,在一個標籤指向錯誤的目的地? (例如,調用'example.com/A/B/C'的麪包屑爲 「C」 點'example.com/C'?然後,它會因爲'$基地$ crumb','$ crumb'是當只有當前一個,但你需要的所有屑到現在還完整路徑 – Aufziehvogel 2012-01-15 17:58:38
爲什麼你的.htaccess將其標記爲 – Fredrik 2012-01-15 19:02:05