фрагменты кода — необходимо добавить URL в php breadcrumb для страницы, на которой они появляются

Я получил сообщение об ошибке из фрагментов Google Rich, потому что отсутствует ссылка на страницу, на которой отображается страница; Что мне нужно добавить в этот скрипт, чтобы получить 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>

0

Решение

Наконец я обнаружил, что структурированные данные Google (богатые фрагменты) на самом деле хотят, чтобы я добавил itemprop = «url» и использовал только
<span itemscope itemtype="http://data-vocabulary.org/Breadcrumb"> один раз. Вот правильный код для php rich snippets хлебных крошек.

    <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>
0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector