我為面包屑使用以下代碼:<?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' )); ?>頁面標(biāo)題是每個頁面頂部的變量。輸出是正確的,并顯示:首頁 / 關(guān)于 / 更多 但是,每個上的鏈接如下所示:Home: example.orgAbout: example.org/aboutMore: example.org/more.php我正在尋找這樣的輸出:example.org/about/more.php
1 回答

波斯汪
TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超4個贊
您可以在循環(huán)中連接鏈接...
$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 關(guān)注
- 104 瀏覽
添加回答
舉報
0/150
提交
取消