[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Site 5 * @subpackage mod_breadcrumbs 6 * 7 * @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 */ 10 11 defined('_JEXEC') or die; 12 13 use Joomla\CMS\HTML\HTMLHelper; 14 use Joomla\CMS\Language\Text; 15 use Joomla\CMS\Router\Route; 16 use Joomla\CMS\Uri\Uri; 17 use Joomla\CMS\WebAsset\WebAssetManager; 18 19 ?> 20 <nav class="mod-breadcrumbs__wrapper" aria-label="<?php echo htmlspecialchars($module->title, ENT_QUOTES, 'UTF-8'); ?>"> 21 <ol class="mod-breadcrumbs breadcrumb px-3 py-2"> 22 <?php if ($params->get('showHere', 1)) : ?> 23 <li class="mod-breadcrumbs__here float-start"> 24 <?php echo Text::_('MOD_BREADCRUMBS_HERE'); ?>  25 </li> 26 <?php else : ?> 27 <li class="mod-breadcrumbs__divider float-start"> 28 <span class="divider icon-location icon-fw" aria-hidden="true"></span> 29 </li> 30 <?php endif; ?> 31 32 <?php 33 // Get rid of duplicated entries on trail including home page when using multilanguage 34 for ($i = 0; $i < $count; $i++) { 35 if ($i === 1 && !empty($list[$i]->link) && !empty($list[$i - 1]->link) && $list[$i]->link === $list[$i - 1]->link) { 36 unset($list[$i]); 37 } 38 } 39 40 // Find last and penultimate items in breadcrumbs list 41 end($list); 42 $last_item_key = key($list); 43 prev($list); 44 $penult_item_key = key($list); 45 46 // Make a link if not the last item in the breadcrumbs 47 $show_last = $params->get('showLast', 1); 48 49 $class = null; 50 51 // Generate the trail 52 foreach ($list as $key => $item) : 53 if ($key !== $last_item_key) : 54 if (!empty($item->link)) : 55 $breadcrumbItem = HTMLHelper::_('link', Route::_($item->link), '<span>' . $item->name . '</span>', ['class' => 'pathway']); 56 else : 57 $breadcrumbItem = '<span>' . $item->name . '</span>'; 58 endif; 59 echo '<li class="mod-breadcrumbs__item breadcrumb-item' . $class . '">' . $breadcrumbItem . '</li>'; 60 elseif ($show_last) : 61 // Render last item if required. 62 $breadcrumbItem = '<span>' . $item->name . '</span>'; 63 $class = ' active'; 64 echo '<li class="mod-breadcrumbs__item breadcrumb-item' . $class . '">' . $breadcrumbItem . '</li>'; 65 endif; 66 endforeach; ?> 67 </ol> 68 <?php 69 70 // Structured data as JSON 71 $data = [ 72 '@context' => 'https://schema.org', 73 '@type' => 'BreadcrumbList', 74 'itemListElement' => [] 75 ]; 76 77 // Use an independent counter for positions. E.g. if Heading items in pathway. 78 $itemsCounter = 0; 79 80 // If showHome is disabled use the fallback $homeCrumb for startpage at first position. 81 if (isset($homeCrumb)) { 82 $data['itemListElement'][] = [ 83 '@type' => 'ListItem', 84 'position' => ++$itemsCounter, 85 'item' => [ 86 '@id' => Route::_($homeCrumb->link, true, Route::TLS_IGNORE, true), 87 'name' => $homeCrumb->name, 88 ], 89 ]; 90 } 91 92 foreach ($list as $key => $item) { 93 // Only add item to JSON if it has a valid link, otherwise skip it. 94 if (!empty($item->link)) { 95 $data['itemListElement'][] = [ 96 '@type' => 'ListItem', 97 'position' => ++$itemsCounter, 98 'item' => [ 99 '@id' => Route::_($item->link, true, Route::TLS_IGNORE, true), 100 'name' => $item->name, 101 ], 102 ]; 103 } elseif ($key === $last_item_key) { 104 // Add the last item (current page) to JSON, but without a link. 105 // Google accepts items without a URL only as the current page. 106 $data['itemListElement'][] = [ 107 '@type' => 'ListItem', 108 'position' => ++$itemsCounter, 109 'item' => [ 110 'name' => $item->name, 111 ], 112 ]; 113 } 114 } 115 116 if ($itemsCounter) { 117 /** @var WebAssetManager $wa */ 118 $wa = $app->getDocument()->getWebAssetManager(); 119 $wa->addInline('script', json_encode($data, JSON_UNESCAPED_UNICODE), [], ['type' => 'application/ld+json']); 120 } 121 ?> 122 </nav>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |