I have a really hard time grasping the concept of creating a category tree. This is the criterias:
- Create an parent/child HTML unordered list with unlimited depth
- Remove all items with status = 0 and any children
- Create URL e.g. /clothes/jeans
- Optional: Generating breadcrumb
The closest solution I could find just made me more confused because I couldn't make them work:
- Convert a series of parent-child relationships into a hierarchical tree?
- Creating a recursive category tree function
Here is my array:
Array
(
[0] => Array
(
[id] => 1
[parent] => 0
[status] => 2
[slug] => clothes
[title] => Clothes
)
[1] => Array
(
[id] => 2
[parent] => 1
[status] => 2
[slug] => jeans
[title] => Jeans
)
[2] => Array
(
[id] => 3
[parent] => 1
[status] => 2
[slug] => dresses
[title] => Dresses
)
[3] => Array
(
[id] => 4
[parent] => 0
[status] => 2
[slug] => accessories
[title] => Accessories
)
[4] => Array
(
[id] => 5
[parent] => 4
[status] => 2
[slug] => bags
[title] => Bags
)
[5] => Array
(
[id] => 6
[parent] => 4
[status] => 2
[slug] => watches
[title] => Watches
)
[6] => Array
(
[id] => 7
[parent] => 6
[status] => 2
[slug] => rolex
[title] => Rolex
)
)
This is the Unordered list I want:
<ul>
<li><a href="/clothes">Clothes</a>
<ul>
<li>
<a href="/clothes/jeans">Clothes</a>
</li>
<li>
<a href="/clothes/dresses">Clothes</a>
</li>
</ul>
</li>
<li><a href="/accessories">Accessories</a>
<ul>
<li>
<a href="/accessories/bags">Bags</a>
</li>
<li>
<a href="/accessories/watches">Watches</a>
<ul>
<li>
<a href="/accessories/watches/rolex">Rolex</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
? Tried to figure out how to with no luck.
– Cudos Nov 11 '12 at 16:53