0

I have set up a block that shows up on the relevant pages that shows up other nodes with the same taxonomy terms (by means of contextual filters that take the argument from a given page).

Can I add a breadcrumb to the header of this block view? I have Crumbs installed.

Example Case:
This is a commerce site, and all the products are tagged by 2 vocabularies: "category" and "collection". Items that share a category tag are "internally similar" (say, all the apples), while "collection" tage are whose that the seller wants to present as similar (say, an apple and a specialized apple knife).
At the bottom of the product page are two blocks (views, contextual filters that take term argument from page) that display products that share both respective taxonomy terms with the main product on the page, and I want those to have a "taxonomy breadcrumb": not only a title with the (linked) tag name, but also its parents (s).
I have actually achieved that functionality by adding a views attachment to the block views.

8
  • Should this be a secondary breadcrumb in addition to and different from the main breadcrumb? What should the breadcrumb items be?
    – donquixote
    Aug 16, 2014 at 4:38
  • The blocks are on the product page. There are two vocabularies per product (the first taxonomy is for "kind of object", the second for "collection"). I have 2 blocks that display the products that share the terms in respective vocabularies). I want them to have their own taxonomy - based breadcrumbs.
    – Dalmaz
    Aug 16, 2014 at 8:47
  • can you give an example?
    – donquixote
    Aug 16, 2014 at 10:41
  • @donquixote: I edited the main post to be more specific
    – Dalmaz
    Aug 16, 2014 at 11:33
  • so e.g. you want block 1 have the breadcrumb "Categories > Fruit > Apples", and the other has "Collections > Kitchen > Apple-related" ?
    – donquixote
    Aug 16, 2014 at 13:25

1 Answer 1

1

I think this could be done with Crumbs programmatically, but this might be overkill. It would also be fragile, because it would depend on Crumbs functionality that is not really part of the public API, so could change in future versions of Crumbs.
Also consider that you don't really need the full breadcrumb, just the taxonomy trail.

Instead, you could write a custom Views header plugin. Unfortunately it is a bit hard to find documentation on that.

Or, you could alter the views header with one of the views hooks.

Or you could use the theme layer to override the views theme output for this specific view.

Or override the block template for the specific block. I think this one is actually the easiest for a starter, and for this specific situation. You can get the taxonomy term from the node, and you get the node with menu_get_object().

Have a look at https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.pages.inc/function/taxonomy_term_page/7 to see how the taxonomy page calculates a breadcrumb based on the taxonomy hierarchy.

(I am mentioning more than one solution here, because other readers might have slightly different requirements.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.