Hello,

I try to create a hierarchical taxonomy breadcrumb for a specific node type.

Here is the example. This is my taxonomy

[Vocabulary]
- Term 1
- Sub Term 1
- Sub Sub Term 1
- Sub Sub Term 2
- Sub Term 2
- Sub Term 3
- Term 2
etc...

Lets imagine that my node is associated to the Sub Sub Term 2.

I would like a breadcrumb like this : Home > Term 1 > Sub Term 1 > Sub Sub Term 2 > Node title

So, concretely, I want that all parent terms become a breadcrumb item.

Not sure what is the token I should use to get that results.

Any help would be greatly appreciated :)

Regards,

Alex

Comments

spleshka’s picture

Hi,

See how to do that on the screenshot: http://drupalace.ru/sites/default/files/pictures/path_breadcrumbs_0.png

Your breadcrumbs should look like that (field-category is field in node with taxonomy terms):

Link title Link path
%node:field-category:parent:parent:name %node:field-category:parent:parent:url
%node:field-category:parent:name %node:field-category:parent:url
%node:field-category:name %node:field-category:url
zmove’s picture

Hi, thank you for your answer.

So, if I don't know what is the future size of the taxonomy hierarchy, I have to repeat that many times to be sure that all the path will be covered ?

Would it be possible to have a token to make a loop into the hierarchy, to cover all possible levels in one line ?

Regards,

Alex

spleshka’s picture

Status: Active » Postponed

Unfortunatelly, for now it is not possible. But I will work on this problem after some bundle of more important features.

petu’s picture

Hello guys!

This case is also actual for me.
I have a solution. Add a breadcrumb's "rule" for each level and show one of them for current depth.
So, you should:

  1. Determine the vocabulary maximum depth (possible depth). Let it be 4.
  2. Add a simple function to template.php:
    function term_depth($tid) {
        $parent = db_query("SELECT parent FROM {taxonomy_term_hierarchy} WHERE tid = :tid", array(':tid' => $tid))->fetchField();
        if($parent == 0) {
            return 1;
        }else  {
            return 1+term_depth($parent);
        }
    }

    It determines the term's depth by tid.

  3. Add 4 rules - one for each level. For each "rule" add PHP-code as a conditions.
    if(term_depth($contexts['tid']->data->tid) == 3){
     return TRUE;
    } else {
     return FALSE;
    }

    where the number is the depth.

Note: you should adopt $contexts['tid']->data->tid for your case. in my case I use taxonomy terms as a page.

Use dsm($contexts) from devel module to find out how to get tid.

In spite of this solution, I'm waiting for the functionality with a loop into the hierarchy from Eugeniy!

Tony Finlay’s picture

I have a similar issue.

I have a content type called: "project".

Within that content type there is a taxonomy field called "field-project-type"

I want my breadcrumb to show the following:

projects/field-project-type-name/project-title

Below is what I currently have, but it throws up a white screen:

$path_breadcrumb = new stdClass();
$path_breadcrumb->api_version = 1;
$path_breadcrumb->machine_name = 'projects';
$path_breadcrumb->name = 'Projects';
$path_breadcrumb->path = 'node/%node';
$path_breadcrumb->data = array(
  'titles' => array(
    0 => 'Projects',
    1 => '%node:field-project-type:1:name',
    2 => '%node:title',
  ),
  'paths' => array(
    0 => 'projects',
    1 => '%node:field-project-type:1:url',
    2 => '<none>',
  ),
  'home' => 1,
  'translatable' => 0,
  'arguments' => array(
    'node' => array(
      'position' => 1,
      'argument' => 'entity_id:node',
      'settings' => array(
        'identifier' => 'Node: ID',
      ),
    ),
  ),
  'access' => array(
    'plugins' => array(
      0 => array(
        'name' => 'node_type',
        'settings' => array(
          'type' => array(
            'project_page' => 'project_page',
          ),
        ),
        'context' => 'node',
        'not' => FALSE,
      ),
    ),
    'logic' => 'and',
  ),
);
$path_breadcrumb->weight = -99;



Cheers in advance for any help.

mropanen’s picture

I can't get tokens (or keywords or whatever these are called in ctools) like %node:field-section:name or %node:field-section:url to work at all, and because of this the solution in #1 doesn't work.
Here :field-section is a taxonomy term in the node.
What it returns is "Name of the term":name and "Name of the term":url

I have Entity API and Entity Tokens 1.0 enabled.

spleshka’s picture

Try to update to the latest Ctools dev.

mropanen’s picture

Thank you, I hadn't realized the latest stable release was so old. Works perfectly now :)

Lemontonix’s picture

Hi,

I am having a similar issue. I am trying to use PB together with Advanved Forum.

The forum is nothing more than nodes having a hierierchial taxonomy based structure.

My breadcrumbs look like this:

$path_breadcrumb = new stdClass();
$path_breadcrumb->api_version = 1;
$path_breadcrumb->machine_name = 'forum';
$path_breadcrumb->name = 'Forum';
$path_breadcrumb->path = 'forum/%forum';
$path_breadcrumb->data = array(
  'titles' => array(
    0 => '%forum:taxonomy-forums:parent:parent:name',
    1 => '%forum:taxonomy_forums:parent:name',
    2 => '%forum:name',
  ),
  'paths' => array(
    0 => '%forum:taxonomy-forums:parent:parent:url',
    1 => '%forum:taxonomy_forums:parent:url',
    2 => '<none>',
  ),
  'home' => 0,
  'translatable' => 0,
  'arguments' => array(
    'forum' => array(
      'position' => 1,
      'argument' => 'forum_id',
      'settings' => array(
        'identifier' => 'Forum: ID',
        'breadcrumb' => 1,
      ),
    ),
  ),
  'access' => array(
    'plugins' => array(),
    'logic' => 'and',
  ),
);
$path_breadcrumb->weight = 0;

Breadcrumbs only contain the %forum:name but not the taxonomy path.

Does anyone know what the problem is? Thanks.

vlad.dancer’s picture

Hi, guys!
Here code that works for me:

function MODULENAME_path_breadcrumbs_view_alter(&$breadcrumbs, $path_breadcrumbs, $contexts) {
  $parents_key = NULL;
  $token_name = '%taxonomy-term:parents-all';

  if (isset($contexts['node'])) {
    $field_product_category_values = field_get_items('node', $contexts['node']->data, 'field_product_category');
    $tid = $field_product_category_values[0]['tid'];
  }
  elseif (isset($contexts['taxonomy_term'])) {
    $tid = $contexts['taxonomy_term']->argument;
  }
  
  $parents_key = array_search($token_name, $path_breadcrumbs->titles);
  $path_breadcrumbs->home ? $offset = $parents_key + 1 : $offset = $parents_key;

  if (is_numeric($parents_key) && $path_breadcrumbs->paths[$parents_key] == $token_name) {
    $parents_entities = array_reverse(taxonomy_get_parents_all($tid));
    !isset($contexts['node']) ? array_pop($parents_entities) : '';

    foreach($parents_entities as $parent) {
      $taxonomy_line[] = l($parent->name , 'shop/'. $parent->tid);
    }

    $breadcrumbs_end = array_splice($breadcrumbs, $offset);
    array_splice($breadcrumbs, $offset, count($taxonomy_line), $taxonomy_line);
    $breadcrumbs = array_merge($breadcrumbs, $breadcrumbs_end);
  }
}

I hope this solution helps someone.

kalabro’s picture

Status: Postponed » Needs review
StatusFileSize
new1.09 KB
new3.68 KB

Just added support for new token "pb-join" which works only with taxonomy terms and adds full taxonomy hierarchy to breadcrumbs.
:name and :url tokens now have to be used in combination.

2013-08-01_01-53-51.png

Result:

2013-08-01_01-59-45.png

Commited to 7.x-3.x: http://drupalcode.org/project/path_breadcrumbs.git/commitdiff/a262c70211...

OnkelTem’s picture

pb-join adds the link to the current term while Drupal default behavior is NOT to have current page in the breadcrumbs. This should be an option.

Also, I tried to emulate not adding current page by providing %term:parent:0:pb-join:name(or url), but this doesn't work for some reason.

kalabro’s picture

@OnkelTem,
try %term:parent:pb-join:name and %term:parent:pb-join:url without number suffixes.

OnkelTem’s picture

Thank you very much! It works. But why it's not expanded like that when selecting via UI?

kalabro’s picture

Status: Needs review » Fixed

@OnkelTem, not all tokens fully expanded in UI. We are working on it. I've fixed ":parent:" token in latest dev: http://drupalcode.org/project/path_breadcrumbs.git/commit/2a69359

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

selinav’s picture

Issue summary: View changes

Hello

I have the same problem. I've read the documentation and I don't understand the right syntax,

I have a content type "produit" with taxonomy term with only one level (field_tags).
When I try to enter this, nothing display
%node:field_tags:pb-join:name and %node:field_tags:pb-join:url

What is wrong ?

Thanks for your help

selinav’s picture

StatusFileSize
new441.36 KB

Here my settings, is-it good ?

kalabro’s picture

Hello, @selinav!

What do you expect to see?
field_tags usually is array of multiple terms:

array(
  0 => 'tag1',
  1 => 'tag2',
  2 => 'tag3',
)

So tokens are provided in this way:
%node:field_tags:0:name / %node:field_tags:0:url for the first tag.
%node:field_tags:1:name / %node:field_tags:1:url for the second tag.
And so on.

pb-join doesn't implode tags in this manner "tag1, tag2, tag3". This token is used for outputting term parents.

selinav’s picture

I have succeed, my problem is due to an error of the name field.
In content type "produit", the name is "field_tags" but the syntax use for path breadcrumb is "field-tags".

I've entered this : %node:field-tags:0:i18n-name and %node:field-tags:0:url

Thank you for your quick reply and the explanation.

grenuy’s picture

Сколько времени прошло, а помогло) спасибо