亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

PHP 痕跡導航數組,鏈接未滿

PHP 痕跡導航數組,鏈接未滿

PHP
繁花如伊 2022-09-30 16:20:18
我為面包屑使用以下代碼:<?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;

    }

}


查看完整回答
反對 回復 2022-09-30
  • 1 回答
  • 0 關注
  • 113 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號