Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>From what you've described, it sounds like you want to implement bread crumbs/categories rather than directories.</p> <p>If this is the case, you'd basically need to create a Categories table in your database like so:</p> <pre><code>Categories id | parent_id | name 1 | 0 | Home 2 | 1 | Garden 3 | 1 | Furniture 4 | 1 | Plumbing 5 | 2 | Lawn Care </code></pre> <p>This would equate to a hierarchy like the following:</p> <ul> <li>Home <ul> <li>Garden <ul> <li>Lawn Care</li> </ul></li> <li>Furniture</li> <li>Plumbing</li> </ul></li> </ul> <p>So if I want to have a product show, for instance, in <em>Home > Garden > Lawn Care</em>, I'll need to link the product to Category #5 (Lawn Care). Then I need to develop a function to do a little while loop that figures out the parent structure from there. It will need to loop until it doesn't find a parent (or until parent_id = 0). In other words, it would go:</p> <pre><code>I'm in Lawn Care. Does Lawn Care have a parent? Yes -&gt; Garden. Does Garden have a parent? Yes -&gt; Home. Does Home have a parent? No -&gt; End. </code></pre> <p>There are a number of ways to implement this, which is why I left specifics out.</p> <p>Alternatively, you could just do this calculation on save of the product or category so it can map out the hierarchy the one time instead of every time (saving on calculations), but this would be a very simple solution that could work for a large number of products.</p> <p>The benefit to doing it this way is that you can also implement product lists based on the category you're in, and from another perspective, you can create product counts per category.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload