简体   繁体   English

如何仅从主页上的面包屑中删除结尾的双箭头“»”

[英]How to remove the trailing double arrows “»” from breadcrumbs on the home page only

I found this useful PHP snippet and made a couple small modifications, but I have not been able to figure out how to exclude the home page from showing the trailing "»" after the word "Home". 我发现了这个有用的PHP代码段,并进行了一些小的修改,但是我还无法弄清楚如何排除主页,以免在单词“ Home”之后显示结尾的“»”。 As a result, it ends up looking like this... Home » . 结果,它最终看起来像是... Home»

Is there a simple way to remove this without changing the way the breadcrumbs appear on any other page? 是否有一种简单的方法可以删除此内容,而不会更改面包屑在其他任何页面上的显示方式?

<?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>

You have to remove the separator character that is put each time after "Home". 您必须删除每次放置在“主页”之后的分隔符。 Add it only if there is something after "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){
    ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM