Skip to content

Instantly share code, notes, and snippets.

@AlekVolsk
Last active April 6, 2022 10:10
Show Gist options
  • Save AlekVolsk/1fe1d2add48c40118752f8b5043f19c0 to your computer and use it in GitHub Desktop.
Save AlekVolsk/1fe1d2add48c40118752f8b5043f19c0 to your computer and use it in GitHub Desktop.
Correct markup for breadcrumbs
<ul itemscope itemtype="http://schema.org/BreadcrumbList">
<li itemscope itemprop="itemListElement" itemtype="http://schema.org/ListItem">
<a title="Наименование сайта" itemprop="item" content="https://site.ru/" href="/">
<span itemprop="name">Главная</span>
</a>
<meta itemprop="position" content="1">
</li>
<li itemscope itemprop="itemListElement" itemtype="http://schema.org/ListItem">
<a title="Наименование раздела" itemprop="item" content="https://site.ru/category" href="/category">
<span itemprop="name">Раздел</span>
</a>
<meta itemprop="position" content="2">
</li>
<li itemscope itemprop="itemListElement" itemtype="http://schema.org/ListItem">
<span title="Текущая страница" itemprop="item" content="https://site.ru/category/currentpage">
<span itemprop="name">Текущая страница</span>
</span>
<meta itemprop="position" content="3">
</li>
</ul>
<?php
use Joomla\CMS\Uri\Uri;
defined('_JEXEC') or die;
echo '<ul itemscope itemtype="http://schema.org/BreadcrumbList">';
if (!$params->get('showLast', 1)) {
array_pop($list);
}
$count = count($list);
$linkCurrent = Uri::current();
$linkRoot = substr(Uri::root(), 0, -1);
for ($i = 0; $i < $count; $i++) {
if ($i == 1 && !empty($list[$i]->link) && !empty($list[$i - 1]->link) && $list[$i]->link == $list[$i - 1]->link) {
continue;
}
if ($pos = strpos($list[$i]->name, '||')) {
$name = trim(substr($list[$i]->name, 0, $pos));
} else {
$name = $list[$i]->name;
}
$meta = '<meta itemprop="position" content="' . ($i + 1) . '">';
if ($i < $count - 1) {
if (!empty($list[$i]->link)) {
$link = explode('?', $list[$i]->link)[0];
echo '<li itemscope itemprop="itemListElement" itemtype="http://schema.org/ListItem"><a itemprop="item" content="' . $linkRoot . $link . '" href="' . $link . '"><span itemprop="name">' . $name . '</span></a>' . $meta . '</li>';
} else {
echo '<li itemscope itemprop="itemListElement" itemtype="http://schema.org/ListItem"><span itemprop="item" content="' . $linkRoot . $link . '"><span itemprop="name">' . $name . '</span></span>' . $meta . '</li>';
}
} else {
echo '<li itemscope itemprop="itemListElement" itemtype="http://schema.org/ListItem"><span itemprop="item" content="' . $linkCurrent . '"><span itemprop="name">' . $name . '</span></span>' . $meta . '</li>';
}
}
echo '</ul>';
{'pdoCrumbs' | snippet : [
'showHome' => 1,
'outputSeparator' => '',
'tplWrapper' => '@INLINE <ul itemscope itemtype="http://schema.org/BreadcrumbList">{$output}</ul>',
'tplHome' => '@INLINE
<li itemscope itemprop="itemListElement" itemtype="http://schema.org/ListItem">
<a title="{$_modx->config.site_name}" itemprop="item" content="{$_modx->config.site_url}" href="{$link}">
<span itemprop="name">{$menutitle}</span>
</a>
<meta itemprop="position" content="{$idx}">
</li>',
'tpl' => '@INLINE
<li itemscope itemprop="itemListElement" itemtype="http://schema.org/ListItem">
<a title="{$menutitle}" itemprop="item" content="{$_modx->config.site_url}{$link}" href="{$link}">
<span itemprop="name">{$menutitle}</span>
</a>
<meta itemprop="position" content="{$idx}">
</li>',
'tplCurrent' => '@INLINE
<li itemscope itemprop="itemListElement" itemtype="http://schema.org/ListItem">
<span title="{$menutitle}" itemprop="item" content="{$_modx->config.site_url}{$link}">
<span itemprop="name">{$menutitle}</span>
</span>
<meta itemprop="position" content="{$idx}">
</li>'
]}
@ivansorlov
Copy link

Понял, в принципе, я так и думал что-то с версией связано

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment