LemonStand Forum: Breadcrumbs - LemonStand Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Breadcrumbs A fairly in-depth Breadcrumbs partial.

#1 User is offline   Phil 

  • Lemonholic
  • PipPipPipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 228
  • Joined: 13-January 10
  • LocationCumberland, BC, Canada

Posted 02 February 2012 - 06:36 PM

Hopefully this code to generate breadcrumbs helps some of you out. Because of how I generate the category tree and pull page information you'll like want to put it in partial and cache it fairly heavily. At the bottom in the join() function you'll want to replace the ' » ' with whatever separator you'd like to use. Anyway, enjoy :)

<?
	$nodes = array(
		root_url('/') => 'Home',
	);
	$parents = $this->page->navigation_parents(false);
	$params = array();
	foreach ($parents as $parent) {
		$page_obj = Cms_Page::findByUrl($parent->url, $params);
		$add_node = true;
		switch ($page_obj->action_reference) {
			case 'shop:category':
			case 'shop:product':
			$add_node = false;
		}
		if ($add_node) {
			$nodes[root_url($page_obj->url)] = $page_obj->navigation_label();
		}
	}

	switch ($this->page->action_reference) {
		case 'blog:post':
			if (isset($post))
				$nodes[root_url('/blog/category/'.$post->categories[0]->url_name)] = $post->categories[0]->name;
		case 'blog:category':
			if (isset($category))
				$nodes[$category->url_name] = $category->name;
			break;
		case 'shop:category':
			if (isset($category))
				$category_nodes = $category->get_parents(false);
		case 'shop:product':
			if (isset($product))
				$category_nodes = $product->category_list[count($product->category_list)-1]->get_parents(true);
			if (isset($category_nodes))
				foreach($category_nodes as $n)
					$nodes[$n->page_url('/shop/category')] = $n->name;
			break;
	}

	$navigation_nodes = array();
	foreach ($nodes as $url => $title) {
		$navigation_nodes[] = "<a href=\"{$url}\">{$title}</a>";
	}
	$navigation_nodes[] = '<a href="'.Phpr::$request->getCurrentUri().'" class="current">' . $this->page->title . '</a>';
?>

<?= join(' &raquo; ', $navigation_nodes) ?>



2012.02.02 - Added support for blog posts/categories.

This post has been edited by Phil: 02 February 2012 - 07:27 PM

1

#2 User is offline   Eric Muyser 

  • Web Developer
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 1,317
  • Joined: 04-August 10
  • LocationVancouver, Canada

Posted 22 February 2012 - 04:55 PM

It's pretty cool, thanks Phil. :)

https://gist.github.com/1888794

Changes:
* Use navigation label for last node.
* Iterate shop category nodes.
* Fix blog category and post.
* Don't show last node for dynamic actions.

Note: I'm using /news for blog, and /store for shop.
0

#3 User is offline   jaybee 

  • LemonEvangelist
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 123
  • Joined: 11-January 10
  • LocationBristol, UK

Posted 28 April 2012 - 07:06 AM

Hi Phil / Eric,

This works great, but I can't figure out how to get this to work when a product is listed under multiple nested categories.

For example, I have this structure:

- Men
- - Clothing
- - - T-Shirts
- - - - Product

- Women
- - Clothing
- - - T-Shirts
- - - - Product


So, for a product listed under 3 categories (Men, Clothing, T-Shirts) the breadcrumbs on the product page correctly outputs:

Home > Men > Clothing  > T-Shirts > Product


...but for a product listed under 6 categories (Men, Clothing, T-Shirts, Women, Clothing, T-Shirts) the breadcrumbs on the product page currently outputs:

Home > Men > Product


Any idea how can I get the breadcrumbs to show the correct structure, if the product belongs to additional categories from the top level?

Home > Men > Clothing > T-Shirts > Product

0

#4 User is offline   apepp 

  • LemonElite
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 824
  • Joined: 30-October 11

Posted 04 May 2012 - 11:02 AM

...mmmm...agreed, i think navigation and breadcrumb can be a tricky one at times...it would be great if Lemonstand had a definitive breadcrumb module of some kind...for the slightly less adept...

...not sure myself about the general consensus on the subject or the implications of even getting a user friendly and flexible solution as other opensource CMS systems try to provide by way of "add ons", (the Wayfinder module of modx for one example).
0

#5 User is offline   jaybee 

  • LemonEvangelist
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 123
  • Joined: 11-January 10
  • LocationBristol, UK

Posted 12 May 2012 - 10:36 AM

View Postapepp, on 04 May 2012 - 11:02 AM, said:

...mmmm...agreed, i think navigation and breadcrumb can be a tricky one at times...it would be great if Lemonstand had a definitive breadcrumb module of some kind...for the slightly less adept...

...not sure myself about the general consensus on the subject or the implications of even getting a user friendly and flexible solution as other opensource CMS systems try to provide by way of "add ons", (the Wayfinder module of modx for one example).


+1 here for your suggestion Ape.

I cannot seem to get a solution sorted for this problem.

Me and my client are happy to pay for a working implementation if anyone can fathom it.
0

Share this topic:


Page 1 of 1

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users