-
-
Save bsakhanov/e2ad6860903f7f38ecbe33b449512d45 to your computer and use it in GitHub Desktop.
Correct markup for breadcrumbs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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>'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{'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>' | |
]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment