Question

What would be the best way to implement a hierarchical structure like this:

  • (A) Taxonomy term from single vocabulary
    • (B) Some content type with parent of type A
      • (C) Some content type with parent of type B

There are reference fields from (B) to (A) and from (C) to (B) but not from (C) to (A).

Basically i need to implement something like this:

Topic (taxonomy term)
|___ Subtopic (custom content type)
         |___ Page (custom content type)
         |___ Page (custom content type)
         |___ + N
|___ Subtopic (custom content type)
         |___ Page (custom content type)
         |___ Page (custom content type)
         |___ + N

I tried using entity reference in all flavours but with not much success. I don't know how to:

  • Implement path aliasing when i add content of type (C) so i have hostname/(A)/(B)/(C) so i don't have to enter the url manually (tried with url patterns but couldn't do it)
  • Create a view that displays content belonging to (C) with Context Filters on hostname/(A)/(B)/(C) url

Any help is much appreciated!

Was it helpful?

Solution

The most suitable structure in your case seems to be to create two-level Taxonomy for your Topic and Subtopic, and a Content Type with Taxonomy term Entity Reference Field.

If you want to limit which Taxonomy level appears when creating new nodes you can configure the Entity Reference field to use the Views Entity reference Display that filters and shows only the second level.

Use Pathauto module to set up automatic URL patterns based on the Taxonomy field and node title.

With Views you can create a Page with Contextual filters for the Taxonomy with Depth or Parent term, and the actual term the node is tagged with. These are two Contextual filters, each gives you one argument in the path.

With the first Contextual filter you filter out all the nodes that are tagged with the the child of the parent from the first URL argument. When you add the second Contextual you narrow it down to the particular Child term.

The third Contextual can be added for the node title, or node ID.

ER fields store entity IDs, not their names, so if you want the actual names in the path as arguments, and not the ID numbers, you'll have to add the Relationship for the ER field. This will open up more options in Views for the Vocabulary fields.

The solution I've described isn't trivial. If you're inexperienced in setting up Contextual filters try to practise first on simple examples. You can find many examples here with answers about Contextuals, Names, and Relationships.

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top