0

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!

  • It seems like your Subtopic should be a level under the Topic in the same Vocabulary. Or can your Subtopics belong to more than one Topic? – prkos Jun 19 at 1:09
  • Thanks for your comment. Subtopics can't belong to more than one topic, only one. – 3ND Jun 19 at 11:09
  • Subtopic content type has substantial number of fields so i wanted to avoid adding it as taxonomy term, if my reasoning is good. – 3ND Jun 19 at 11:18
1

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.

| improve this answer | |
  • Thanks! What if i didn't have requirement to have topics as main taxonomy? Is it possible to have for example three nested content types? Topic -> Subtopic -> Page. – 3ND Jun 22 at 13:12
  • 1
    Yes, of course you can have many levels of entity references (chains). You can still create different combinations of Views results that are structured that way, it is a bit more complicated with more levels, and you have to be careful about performance if you have a lot of nodes. – prkos Jun 22 at 21:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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