Last active
April 6, 2022 10:10
-
-
Save AlekVolsk/1fe1d2add48c40118752f8b5043f19c0 to your computer and use it in GitHub Desktop.
Correct markup for breadcrumbs
This file contains 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 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>' | |
]} |
В 3.6.2 нет нэймспейсов, поэтому и не работало. Код написан для версии 3.8+
Так что вы все правильно поправили у себя, переписав на JUri
Понял, в принципе, я так и думал что-то с версией связано
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Вначале прописал, потом закомментировал и без неё работает.
Версия Joomla! 3.6.2 Stable