Я использую этот код ниже на моем сайте для обработки хлебных крошек, Проблемы с этим кодом, что я получаю все время ту же иерархию, а не истинный ..Breadcrumbs не работает
, например: Ссылка hxxp://fakesite.com/A/B/C/d
он будет печатать:
Главная »A» B »C» 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'? Тогда это будет из-за '$ base $ crumb'.' $ crumb' только текущий, но вам нужен полный путь всех крошек до сих пор. – Aufziehvogel
Почему вы отметили его с помощью .htaccess? – Fredrik