Как убрать висячие двойные стрелки & quot; »& quot; только из крошек на главной странице

Я нашел этот полезный фрагмент PHP и сделал несколько небольших модификаций, но я не смог выяснить, как исключить показ домашней страницы после завершающего слова «» »после слова« Home ». В результате это выглядит так … Главная « .

Есть ли простой способ удалить это, не изменяя способ, которым панировочные сухари появляются на любой другой странице?

<?php

function breadcrumbs($sep = ' &raquo; ', $home = 'Home') {
//Use RDFa breadcrumb, can also be used for microformats etc.
$bc     =   '<div xmlns:v="http://rdf.data-vocabulary.org/#" id="crums">'.$text;
//Get the website:
$site   =   'http://'.$_SERVER['HTTP_HOST'];
//Get all vars en skip the empty ones
$crumbs =   array_filter( explode("/",$_SERVER["REQUEST_URI"]) );
//Create the home breadcrumb
$bc    .=   '<span typeof="v:Breadcrumb"><a href="'.$site.'" rel="v:url" property="v:title">'.$home.'</a>'.$sep.'</span>';
//Count all not empty breadcrumbs
$nm     =   count($crumbs);
$i      =   1;
//Loop the crumbs
foreach($crumbs as $crumb){
//Make the link look nice
$link    =  ucfirst( str_replace( array(".php","-","_"), array(""," "," ") ,$crumb) );
//Loose the last seperator
$sep     =  $i==$nm?'':$sep;
//Add crumbs to the root
$site   .=  '/'.$crumb;
//Make the next crumb
$bc     .=  '<span typeof="v:Breadcrumb"><a href="'.$site.'/" rel="v:url" property="v:title">'.$link.'</a>'.$sep.'</span>';
$i++;
}
$bc .=  '</div>';
//Return the result
return $bc;}
?>

<p><?= breadcrumbs() ?></p>

0

Решение

Вы должны удалить символ разделителя, который ставится каждый раз после «Home». Добавляйте его только в том случае, если после «Дома» что-то есть.

$crumbs =   array_filter( explode("/",$_SERVER["REQUEST_URI"]) );

//Count all not empty breadcrumbs
$nm     =   count($crumbs);
$i      =   1;

// Add first separator if there is at least one crumb
$homesep     =  $nm == 0?'':$sep;
//Create the home breadcrumb
$bc    .=   '<span typeof="v:Breadcrumb"><a href="'.$site.'" rel="v:url" property="v:title">'.$home.'</a>'.$homesep.'</span>';

//Loop the crumbs
foreach($crumbs as $crumb){
...
}
2

Другие решения

Других решений пока нет …