Skip to content

Instantly share code, notes, and snippets.

@dardub
Created May 8, 2012 19:42
Show Gist options
  • Save dardub/2638754 to your computer and use it in GitHub Desktop.
Save dardub/2638754 to your computer and use it in GitHub Desktop.
nested breadcrumbs
<!-- start breadcrumbs -->
<? if ( isset($category) && $category instanceof Shop_Category ):
$parent_categories = $category->get_parents(true);
?>
<ol class="breadcrumbs">
<? foreach ($parent_categories as $parent_category): ?>
<li class="<?= $parent_category->id == $category->id ? 'last' : null ?>">
<? if ($parent_category->id != $category->id): ?><a href="<?= $parent_category->page_url('/category') ?>"><? endif ?>
<?= h($parent_category->name) ?>
<? if ($parent_category->id != $category->id): ?></a><? endif ?>
</li>
<? if ( $parent_category->id != $category->id ): ?>
<li>&rarr;</li>
<? endif ?>
<? endforeach ?>
</ol>
<? elseif (isset($product)):
$product_categories = $product->category_list->objectArray;
function sort_product_categories($a, $b, $c='front_end_sort_order')
{
if ($a->$c == $b->$c) return 0;
return ($a->$c < $b->$c) ? 1 : -1;
}
usort ($product_categories, 'sort_product_categories');
$parent_categories = $product_categories[0]->get_parents(true);
?>
<ol class="breadcrumbs">
<? foreach ($parent_categories as $parent_category): ?>
<li>
<a href="<?= $parent_category->page_url('/category') ?>"><?= h($parent_category->name) ?></a>
</li>
<li>&rarr;</li>
<? endforeach ?>
<li class="last"><?= h($product->name) ?></li>
</ol>
<? elseif( isset($manufacturer) && $manufacturer): ?>​
<ol class="breadcrumbs">
<li><a href="<?= root_url('/manufacturer') ?>">Manufacturers</a></li>
<li>&rarr;</li>
<li><? if(isset($category_id)): ?><a href="<?= root_url('/manufacturer/'.$manufacturer->url_name) ?>"><? endif ?>
<?= $manufacturer->name ?>
<? if(isset($category_id)): ?></a><? endif ?>
</li>
<? if(isset($category_id)): ?>
<li>&rarr;</li>
<? $category = Shop_Category::create()->find($category_id); ?>
<li><?= $category->name ?></li>
<? endif ?>
</ol>
<? endif ?>
<!-- end breadcrumbs -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment