0

I am looking to output categories in a level hierarchical format.

I have multiple categories, with different levels of categories. Entries can be related to different levels of those categories.

Here is an example of categories setup in the CMS

 - TV & Home Theater
    |
     - TVs
    |   |
    |    - HD
    |   |
    |    - 4K
    |
     - Streaming Media Players

I want to be able to output the hierarchical format for the categories related in the entries.

For example I would want to output

hierarchicalCategories: [
    {
        lvl0: "TV & Home Theater",
        lvl1: "TVs",
        lvl2: "4K"
    },
    {
        lvl0: "TV & Home Theater",
        lvl1: "Streaming Media Players"
    }
]

The project has a number of top level categories with no format for child categories, some may have no children, others may have 2 or 3.

What is the best way to output this type of category hierarchy?

Your Answer

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

Browse other questions tagged or ask your own question.