Skip to content

Instantly share code, notes, and snippets.

@HaeckDesign
Last active December 16, 2016 06:55
Show Gist options
  • Save HaeckDesign/2b14dfacfddf3e58e35a to your computer and use it in GitHub Desktop.
Save HaeckDesign/2b14dfacfddf3e58e35a to your computer and use it in GitHub Desktop.
Joomla - Schema Friendly Breadcrumbs (mod_breadcrumbs/default.php)
<?php
defined('_JEXEC') or die;
?>
<ol itemscope itemtype="http://schema.org/BreadcrumbList" class="uk-breadcrumb uk-margin uk-link-muted <?php echo $moduleclass_sfx; ?>">
<?php
if ($params->get('showHere', 1))
{
echo '<li itemprop="itemListElement" itemscope
itemtype="http://schema.org/ListItem" class="uk-active">' . JText::_('MOD_BREADCRUMBS_HERE') . '</li>';
}
else
{
echo '<li><i class="uk-icon-home"></i></li>';
}
// Get rid of duplicated entries on trail including home page when using multilanguage
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)
{
unset($list[$i]);
}
}
// Find last and penultimate items in breadcrumbs list
end($list);
$last_item_key = key($list);
prev($list);
$penult_item_key = key($list);
// Make a link if not the last item in the breadcrumbs
$show_last = $params->get('showLast', 1);
// Generate the trail
foreach ($list as $key => $item) :
if ($key != $last_item_key)
{
// Render all but last item - along with separator
echo '<li itemprop="itemListElement" itemscope
itemtype="http://schema.org/ListItem">';
if (!empty($item->link))
{
echo '<a href="' . $item->link . '" title="' . $item->name . '" itemprop="item"><span itemprop="name">' . $item->name . '</span></a>';
}
else
{
echo '<span itemprop="name">' . $item->name . '</span>';
}
if (($key != $penult_item_key) || $show_last)
{
echo '';
}
echo '</li>';
}
elseif ($show_last)
{
// Render last item if reqd.
echo '<li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem" class="uk-active" ><span itemprop="name">';
echo $item->name;
echo '<link itemprop="url" href="' . $item->link . '"/></span></li>';
}
endforeach; ?>
</ol>
@HaeckDesign
Copy link
Author

Joomla breadcrumb module w/ Schema markdown included.
Tested and working on Joomla 3.4.3
(test w/: https://developers.google.com/structured-data/testing-tool/)

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