Save taxonomy term's lineage
In Drupal 7 when editing a node and saving a taxonomy term that has parents, how can I attach the parent lineage to the node as well?
ie:
Honda
-> Civic
Toyota
-> C开发者_运维百科orolla
If I choose Corolla, Toyota would also be attached to the node.
You could use the Hierarchical Select module for this. Enable the "save lineage" setting to achieve it.
You usually don't need to do this; whatever function you'd want for this, would be able to do this programmatically for you. For example, if you want all of these displayed on the page, I know there's a possibility to display the full hierarchy in breadcrumbs - it's either somewhere in core, or a module. If you want searches of "Honda" also to show Civics ... like if you've set up a Views page with an exposed filter for this vocabulary - you'll see that in the options for these filters, there's also an option to show nodes associated with "children" of the taxonomy term you're searching for.
In order to write code yourself for a template file that displays the taxonomy term's parents, see taxonomy_get_parents($tid)
: http://api.drupal.org/api/drupal/modules--taxonomy--taxonomy.module/function/taxonomy_get_parents/7
精彩评论