我为面包屑使用以下代码:
<?php
class Breadcrumb
{
private $breadcrumb;
private $separator = ' / ';
private $domain = 'example.org';
public function build($array)
{
$breadcrumbs = array_merge(array('Home' => ''), $array);
$count = 0;
foreach($breadcrumbs as $title => $link) {
$this->breadcrumb .= '
<span itemscope="" itemtype="https://schema.org/BreadcrumbList">
<a href="'.$this->domain. '/'.$link.'" itemprop="url">
<span itemprop="title">'.$title.'</span>
</a>
</span>';
$count++;
if($count !== count($breadcrumbs)) {
$this->breadcrumb .= $this->separator;
}
}
return $this->breadcrumb;
}
}
?>
我这样称呼它:
<?php
$breadcrumb = new Breadcrumb();
echo $breadcrumb->build(array(
$pageTitle => 'about',
'More' => 'more.php'
));
?>
页面标题是每个页面顶部的变量。
输出是正确的,并显示:首页 / 关于 / 更多 但是,每个上的链接如下所示:
Home: example.org
About: example.org/about
More: example.org/more.php
我正在寻找这样的输出:example.org/about/more.php
波斯汪