| | |
| | | return []; |
| | | } |
| | | |
| | | $key = get_queried_object_id() ?: 'home'; |
| | | $crumbs = $this->cache->get($key); |
| | | switch (true) { |
| | | case is_singular(): |
| | | $key = get_queried_object_id(); |
| | | break; |
| | | case is_post_type_archive(): |
| | | $obj = get_queried_object(); |
| | | $key = $obj->name; |
| | | break; |
| | | case is_tax(): |
| | | $obj = get_queried_object(); |
| | | $key = $obj->taxonomy; |
| | | break; |
| | | default: |
| | | $key = 'home'; |
| | | break; |
| | | } |
| | | |
| | | $crumbs = $this->cache->get($key); |
| | | if ($crumbs !== false) { |
| | | return $crumbs; |
| | | } |
| | | |
| | | $crumbs = $this->buildCrumbs(); |
| | | $crumbs = apply_filters('jvbBreadcrumbs',$crumbs); |
| | | $this->cache->set($key, $crumbs); |
| | | |
| | | return $crumbs; |
| | |
| | | ]; |
| | | |
| | | $obj = get_queried_object(); |
| | | |
| | | if (is_tax()) { |
| | | $crumbs = $this->addTaxonomyCrumbs($crumbs, $obj); |
| | | } elseif (is_singular()) { |
| | |
| | | if (array_key_exists($name, JVB_CONTENT)) { |
| | | $crumbs[] = [ |
| | | 'name' => JVB_CONTENT[$name]['breadcrumb'] ?? JVB_CONTENT[$name]['plural'], |
| | | 'url' => get_post_type_archive_link($type), |
| | | 'url' => get_post_type_archive_link($type) |
| | | ]; |
| | | } |
| | | |
| | |
| | | $out .= '<ol itemscope itemtype="https://schema.org/BreadcrumbList">'; |
| | | |
| | | $position = 1; |
| | | $total = count($crumbs); |
| | | foreach ($crumbs as $crumb) { |
| | | $label = '<span itemprop="name">' . strtolower($crumb['name']) . '</span>'; |
| | | |
| | |
| | | |
| | | // Add link if URL exists and not current page |
| | | if ($crumb['url'] !== false) { |
| | | $isCurrent = isset($crumb['id']) && $crumb['id'] === get_queried_object_id(); |
| | | if (!$isCurrent) { |
| | | if ($total !== $position) { |
| | | $aOpen = '<a itemprop="item" href="' . esc_url($crumb['url']) . '" title="' . esc_attr($crumb['name']) . '">'; |
| | | $aClose = '</a>'; |
| | | } |