Приклад розмітки хлібних крихт за schema.org
<ul itemscope itemtype="https://schema.org/BreadcrumbList">
<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">
<a href="/" title="Головна" itemprop="item">
<span itemprop="name">Головна</span>
<meta itemprop="position" content="1">
</a>
</li>
<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">
<a href="/my-section/" title="Мій Розділ" itemprop="item">
<span itemprop="name">Мій Розділ</span>
<meta itemprop="position" content="2">
</a>
</li>
<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">
<a href="/my-section/page/" title="Сторінка" itemprop="item">
<span itemprop="name">Сторінка</span>
<meta itemprop="position" content="3">
</a>
</li>
</ul>
itemscope - вказує пошуковому боту, що на сторінці описується певний об'єкт.
itemtype - вказує пошуковому боту тип об'єкта.
itemtype="https://schema.org/BreadcrumbList" - вказує тип об'єкта як «хлібні крихти» і складається з ланцюжка пов'язаних веб-сторінок.
itemprop="itemListElement" - вказує на окремий пункт списку поточного об'єкта.
itemprop="item" - розмітка посилання.
itemprop="name" - назва поточного елемента списку, назва хлібної крихти.
meta itemprop="position" content="number" - визначає позицію елемента в навігаційному ланцюжку.
Додаємо мікророзмітку хлібних крихт у Yii1
Створюємо новий віджет хлібних крихт
Для початку створимо клас MyBreadcrumbs.php (app/protected/widgets/MyBreadcrumbs.php), який буде успадковувати базовий клас хлібних крихт CBreadcrumbs, з таким кодом:
<?php
Yii::import('zii.widgets.CBreadcrumbs');
class MyBreadcrumbs extends CBreadcrumbs {
public function run() {
if(empty($this->links)) {
return;
}
$definedLinks = $this->links;
echo CHtml::openTag($this->tagName, $this->htmlOptions)."\n";
$links=array();
if($this->homeLink === null) {
$definedLinks = array(Yii::t('zii', 'Home') => Yii::app()->homeUrl) + $definedLinks;
} else if($this->homeLink !== false) {
$links[] = $this->homeLink;
}
$position = 1;
foreach($definedLinks as $label=>$url) {
if(is_string($label) || is_array($url)) {
$links[] = strtr($this->activeLinkTemplate, array(
'{url}' => CHtml::normalizeUrl($url),
'{label}' => $this->encodeLabel ? CHtml::encode($label) : $label,
'{position}' => $position,
));
} else {
$endLink = str_replace('{position}', $position, $this->inactiveLinkTemplate);
$links[] = str_replace('{label}', $this->encodeLabel ? CHtml::encode($url) : $url, $endLink);
}
$position++;
}
echo implode($this->separator,$links);
echo CHtml::closeTag($this->tagName);
}
}
Викликаємо віджет хлібних крихт із мікророзміткою
Тепер у місці, де викликається стандартний віджет хлібних крихт CBreadcrumbs (зазвичай це: app/themes/themeName/views/layouts/main.php), замінюємо виклик стандартного віджета на наш:
<?php
$this->widget('application.widgets.MyBreadcrumbs', array(
'links' => $this->breadcrumbs,
'homeLink' => '<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><a href="/" itemprop="item"><span itemprop="name">' . Yii::t('main', 'breadcrumbs.mainPage.text') . '</span></a><meta itemprop="position" content="0"></li>',
'tagName' => 'ol',
'separator' => ' ',
'activeLinkTemplate' => '<li title="{label}" itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><a href="{url}" itemprop="item"><span itemprop="name">{label}</span></a><meta itemprop="position" content="{position}"></li>',
'inactiveLinkTemplate' => '<li class="active" title="{label}" itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><span itemprop="name" class="breadcrumb-current">{label}</span><meta itemprop="position" content="{position}"></li>',
'htmlOptions' => array('class' => 'breadcrumb', 'itemscope itemtype' => 'https://schema.org/BreadcrumbList'),
'encodeLabel' => false,
));
Заповнюємо масив хлібних крихт
У контролері масив із хлібними крихтами заповнюється як і раніше:
$this->breadcrumbs = array(
'Мой раздел' => array('/my-section'),
$this->breadcrumbsTitle
);
Як перевірити мікророзмітку на сайті?
Перевірити правильність мікророзмітки на сайті можна за допомогою інструменту від google: https://developers.google.com/search/docs/advanced/structured-data


