我为面包屑使用以下代码:<?phpclass 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.orgAbout: example.org/aboutMore: example.org/more.php我正在寻找这样的输出:example.org/about/more.php
1 回答
波斯汪
TA贡献1811条经验 获得超4个赞
您可以在循环中连接链接...
$bclink = '';
foreach($breadcrumbs as $title => $link) {
if ($link != '') {
$bclink .= '/' . $link;
}
$this->breadcrumb .= '
<span itemscope="" itemtype="https://schema.org/BreadcrumbList">
<a href="'.$this->domain.$bclink.'" itemprop="url">
<span itemprop="title">'.$title.'</span>
</a>
</span>';
$count++;
if($count !== count($breadcrumbs)) {
$this->breadcrumb .= $this->separator;
}
}
- 1 回答
- 0 关注
- 82 浏览
添加回答
举报
0/150
提交
取消