Skip to content

Instantly share code, notes, and snippets.

@kernusr
Created June 1, 2019 15:09
Show Gist options
  • Save kernusr/d9d65661f244bc84758d2d3c82360abd to your computer and use it in GitHub Desktop.
Save kernusr/d9d65661f244bc84758d2d3c82360abd to your computer and use it in GitHub Desktop.
Breadcrumbs template for bitrix with schema org and use bootstrap 4
<nav class="breadcrumb px-0" aria-label="breadcrumb" itemprop="http://schema.org/breadcrumb" itemscope="" itemtype="http://schema.org/BreadcrumbList">
<div class="breadcrumb-item" id="breadcrumb_0" itemprop="itemListElement" itemscope="" itemtype="http://schema.org/ListItem">
<a href="https://my.site/" content="https://my.site/" title="SITE NAME" itemprop="item">
<span itemprop="name">SITE NAME</span>
</a>
<meta itemprop="position" content="1">
</div>
<div class="breadcrumb-item" id="breadcrumb_1" itemprop="itemListElement" itemscope="" itemtype="http://schema.org/ListItem">
<a href="https://my.site/root-section/" content="https://my.site/catalog/" title="ROOT SECTION NAME" itemprop="item">
<span itemprop="name">ROOT SECTION NAME</span>
</a>
<meta itemprop="position" content="2">
</div>
<div class="breadcrumb-item" id="breadcrumb_2" itemprop="itemListElement" itemscope="" itemtype="http://schema.org/ListItem">
<a href="https://my.site/root-section/inherit-section/" content="https://my.site/catalog/absent/" title="INHERIT SECTION NAME" itemprop="item">
<span itemprop="name">INHERIT SECTION NAME</span>
</a>
<meta itemprop="position" content="3">
</div>
<div class="breadcrumb-item active" aria-current="page" itemprop="itemListElement" itemscope="" itemtype="http://schema.org/ListItem">
<span title="ELEMENT NAME" itemprop="item" content="https://my.site/root-section/inherit-section/element/">
<span itemprop="name">ELEMENT NAME</span>
</span>
<meta itemprop="position" content="4">
</div>
</nav>
<?php
if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) {
die();
}
/**
* @global CMain $APPLICATION
* @var array $arParams
* @var array $arResult
*/
global $APPLICATION;
//delayed function must return a string
if (empty($arResult)) {
return "";
}
$strReturn = '';
$strReturn .= '<nav class="breadcrumb px-0" aria-label="breadcrumb" itemprop="http://schema.org/breadcrumb" itemscope itemtype="http://schema.org/BreadcrumbList">';
$items = count($arResult);
$proto = $_SERVER['SERVER_PORT'] == 443 ? 'https://' : 'http://';
$host = $_SERVER['HTTP_HOST'];
$site = $proto . $host;
for ($index = 0; $index < $items; $index++) {
$title = htmlspecialcharsex($arResult[$index]["TITLE"]);
if ($arResult[$index]["LINK"] <> "" && $index != $items - 1) {
$strReturn .= '
<div class="breadcrumb-item" id="breadcrumb_' . $index . '" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
<a href="' . $site . $arResult[$index]["LINK"] . '" content="' . $site . $arResult[$index]["LINK"] . '" title="' . $title . '" itemprop="item">
<span itemprop="name">' . $title . '</span>
</a>
<meta itemprop="position" content="' . ($index + 1) . '" />
</div>';
} else {
$strReturn .= '
<div class="breadcrumb-item active" aria-current="page" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
<span title="' . $title . '" itemprop="item" content="' . $site . $APPLICATION->GetCurUri() . '">
<span itemprop="name">' . $title . '</span>
</span>
<meta itemprop="position" content="' . ($index + 1) . '" />
</div>';
}
}
$strReturn .= '</nav>';
return $strReturn;
@kernusr
Copy link
Author

kernusr commented Jun 1, 2019

Annotation 2019-06-01 180730

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