breadcrumbs code example

Example 1: breadcrumbs shopify

{% unless template == 'index' or template == 'cart' or template == 'list-collections' %}
<nav class="breadcrumb" role="navigation" aria-label="breadcrumbs">
  <a href="/" title="Home">Home</a>
  {% if template contains 'page' %}
    <span aria-hidden="true"></span>
    <span>{{ page.title }}</span>
  {% elsif template contains 'product' %}
    {% if collection.url %}
      <span aria-hidden="true"></span>
      {{ collection.title | link_to: collection.url }}
    {% endif %}
    <span aria-hidden="true"></span>
    <span>{{ product.title }}</span>
  {% elsif template contains 'collection' and collection.handle %}
    <span aria-hidden="true"></span>
    {% if current_tags %}
      {% capture url %}/collections/{{ collection.handle }}{% endcapture %}
      {{ collection.title | link_to: url }}
      <span aria-hidden="true"></span>
      <span>{{ current_tags | join: " + " }}</span>
    {% else %}
      <span>{{ collection.title }}</span>
    {% endif %}
  {% elsif template == 'blog' %}
    <span aria-hidden="true"></span>
    {% if current_tags %}
      {{ blog.title | link_to: blog.url }}
      <span aria-hidden="true"></span>
      <span>{{ current_tags | join: " + " }}</span>
    {% else %}
    <span>{{ blog.title }}</span>
    {% endif %}
  {% elsif template == 'article' %}
    <span aria-hidden="true"></span>
    {{ blog.title | link_to: blog.url }}
    <span aria-hidden="true"></span>
    <span>{{ article.title }}</span>
  {% else %}
   <span aria-hidden="true"></span>
   <span>{{ page_title }}</span>
  {% endif %}
</nav>
{% endunless %}

Example 2: bootstrap breadcrumb

<nav aria-label="breadcrumb">
  <ol class="breadcrumb">
    <li class="breadcrumb-item"><a href="#">Home</a></li>
    <li class="breadcrumb-item"><a href="#">Library</a></li>
    <li class="breadcrumb-item active">Data</li>
  </ol>
</nav>

Example 3: yoast breadcrumbs

<?php
if ( function_exists('yoast_breadcrumb') ) {
  yoast_breadcrumb( '<p id="breadcrumbs">','</p>' );
}
?>

Example 4: wordpress breadcrumbs according to menu structure

// helper function to find a menu item in an array of items
function wpd_get_menu_item( $field, $object_id, $items ){
    foreach( $items as $item ){
        if( $item->$field == $object_id ) return $item;
    }
    return false;
}

function wpd_nav_menu_breadcrumbs( $menu ){
    // get menu items by menu id, slug, name, or object
    $items = wp_get_nav_menu_items( $menu );
    if( false === $items ){
        echo 'Menu not found';
        return;
    }
    // get the menu item for the current page
    $item = wpd_get_menu_item( 'object_id', get_queried_object_id(), $items );
    if( false === $item ){
        return;
    }
    // start an array of objects for the crumbs
    $menu_item_objects = array( $item );
    // loop over menu items to get the menu item parents
    while( 0 != $item->menu_item_parent ){
        $item = wpd_get_menu_item( 'ID', $item->menu_item_parent, $items );
        array_unshift( $menu_item_objects, $item );
    }
    // output crumbs
    $crumbs = array(); 
    foreach( $menu_item_objects as $menu_item ){
        $link = '<a href="%s">%s</a>';
        $crumbs[] = sprintf( $link, $menu_item->url, $menu_item->title );
    }
    echo join( ' > ', $crumbs );
}

Example 5: yoast breadcrumbs

[wpseo_breadcrumb]

Example 6: dotcms breadcrumbs

## Get the Nav item for the current folder
#set($current = $navtool.getNav())

## Build the list of folders to display in the crumbtrail
#set($crumb = $contents.getEmptyList())
#set($_x=$crumb.add(0,$current))
#foreach($item in [1..25])
     #set($current = $current.parent)
     #if($current.title=="System folder")
          #break
     #end
     #set($_x=$crumb.add(0,$current))
#end

## Display the crumbtrail
<ul>
     <li style="display:inline"><a href="/">Home</a></li>
     #foreach($item in $crumb)
          <li style="display:inline">     
               <a href="$item.href">$item.title</a>
          </li>
     #end
</ul>

Tags:

Misc Example