i need to create a collapsible menu tree from taxonomy terms and nodes which belong to them (not nested terms, but content pages) i'm totally stuck about it i've found solutions for nested taxonomy terms only, but not for combined with content pages from the term. meaning menu tree like this:
It's very simple to create the tree structure output you're looking for:
- Create the Content type Views,
- add the Taxonomy term Field next to the Title field,
FormatViews settings choose to group by the Taxonomy field
Grouping field Nr.1
On the Taxonomy field choose
Exclude from display.
This will give you a list of nodes that are displayed in groups by their taxonomy terms.
That's probably an opinion-based thing and actually also a too broad question. But here's what I'd do:
- Programmatically create a new block.
- Provide a
hook_themeand your own template to later render the output the way you want.
- Follow one answer from How to get all node entities tagged with a specific term? to get the data you need.
- In the block's
build()function pass the data to your custom template and build the markup you need.
- Optional: Improve performance by either storing the data from step 3. in some Drupal variable that can be purged from some admin settings form button click. Or add some custom cache tags that get invalidated as soon as taxonomy or node CRUD operations take place.
You probably can achieve what you want with some Views voodoo, and maybe should try that first, depending on your programming skills.
I have a view set up that sounds similar to what I think you are trying to accomplish:
- Create your content view filtering by taxonomy.
- Create your taxonomy view.
- Go back to your content view and use "no results behavior" under "advanced" and insert your taxonomy view into your content view as a "global view area".
Now where there is no content assigned directly to the parent term, your term view appears displaying child terms. You are basically using parent terms and % arguments in your path to set the depth of the "tree".
You will also have to set your child "term page display" under "manage display" to show the content view. It's pretty complicated but VERY functional! I hope this helps!