需要将url添加到它们出现的页面的php面包屑中


Need to add url to php breadcrumb for page on which they appear

我从Google Rich snippets中得到一个错误,因为上显示的页面的面包屑url丢失;我需要向这个脚本添加什么才能获得"最后一个"面包屑上的url。感谢

    <p> <div id="breadcrumb" style="font-variant:small-caps;"><span>
<? 
$path = $_SERVER["PHP_SELF"]; 
$tree = split("/",$path); 
$breadcrumb =  '';
$totalbreadcrumb = '';
$divstring  = '<span itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><span itemprop="title">';
if (count($tree)==2 && $tree[1]=="/index.php") { // First, check if we are on the home page 
    $breadcrumb =  $divstring . "home"; 

} else { // If not, then first put a link to the homepage 
    $breadcrumb = "<a href='"/index.php'">" . $divstring . "home </a>"; 
    $totalbreadcrumb = "home";
    for ($i=1; $i<count($tree); $i++) { // Now step through each level adding a link, until we reach an actual file 
        if (strstr($tree[$i],".")) { // Found a file (i.e. it has a fullstop character in it) 
            if ($tree[$i]!="/index.php") { // If it is not the index page of the current folder, print the name 
                $pagename = split("'.",$tree[$i]); 
                $breadcrumb = $breadcrumb . " &gt; " .  $divstring . str_replace("_"," ",$pagename[0]); 

            } 
        } else { // Found another directory, so provide a link to the top level... 
            if ($tree[$i+1]=="/index.php") { // ...unless the next one down is the index page 
                $breadcrumb = $breadcrumb . " &gt; "  . $divstring  . str_replace("_"," ",$tree[$i]); 

            } else { 
                $breadcrumb = $breadcrumb . " &gt; <a href='""; // Add the arrow between nodes 
                for ($j=1; $j<=$i; $j++) { // Add the right link depth to the actual link 
                    $breadcrumb = $breadcrumb . "/" . $tree[$j]; 

                } 
                $breadcrumb = $breadcrumb . "/'">" .  $divstring . $tree[$i] . "</span></a>";                
            } 
        } 
    } 
} 
  echo  $breadcrumb;  // Print the final breadcrumb trail to the page 
?></div></span></p></div>

我终于发现,谷歌结构化数据(丰富的片段)实际上希望我添加itemprop="url",并且只使用CCD_ 1一次。以下是php丰富的代码片段breadcrumbs的正确代码。

    <p> <div id="breadcrumb" style="font-variant:small-caps;"><span><span itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><span itemprop="title">
<? 
$path = $_SERVER["PHP_SELF"]; 
$tree = split("/",$path); 
$breadcrumb =  '';
$totalbreadcrumb = '';
$divstring  = '<span itemprop="title">';
if (count($tree)==2 && $tree[1]=="/index.php") { // First, check if we are on the home page 
    $breadcrumb =  $divstring . "home"; 

} else { // If not, then first put a link to the homepage 
    $breadcrumb = "<a href='"/index.php'" itemprop='"url'">" . $divstring . "home </a>"; 
    $totalbreadcrumb = "home";
    for ($i=1; $i<count($tree); $i++) { // Now step through each level adding a link, until we reach an actual file 
        if (strstr($tree[$i],".")) { // Found a file (i.e. it has a fullstop character in it) 
            if ($tree[$i]!="/index.php" ) { // If it is not the index page of the current folder, print the name 
                $pagename = split("'.",$tree[$i]); 
                $breadcrumb = $breadcrumb . " &gt; " .  $divstring . str_replace("_"," ",$pagename[0]); 

            } 
        } else { // Found another directory, so provide a link to the top level... 
            if ($tree[$i+1]=="/index.php") { // ...unless the next one down is the index page 
           $breadcrumb = $breadcrumb . " </span> &gt; " . $divstring   . str_replace("_"," ",$tree[$i]); 

            } else { 
                $breadcrumb = $breadcrumb . " &gt; <a href='""; // Add the arrow between nodes 
                for ($j=1; $j<=$i; $j++) { // Add the right link depth to the actual link 
                    $breadcrumb = $breadcrumb . "/" . $tree[$j]; 

                } 
               $divstring .   $breadcrumb = $breadcrumb . "/'" itemprop='"url'">" . $tree[$i] . "</span></a>";                
            } 
        } 
    } 
} 
  echo  $breadcrumb;  // Print the final breadcrumb trail to the page 
?></div></span></p></div>