2

I would like to select just the children of any given main category (eg. Accessories, Stomps in the picture), regardless of segments in my URL.

I've been trying to understand why the code below won't work.

I would like to select just the children of any given main category (eg. Accessories, Stomps

This just won't work. Why?

{% set categoryGroup = craft.categories.group('productTypes').descendantOf('accessories') %}
<ul>
    {% for category in categoryGroup %}
        <li class="category">{{ category.title }}</li>    
    {% endfor %}
</ul>
2

Because the descendantOf function expects a parameter of type ElementInterface or an integer

 /**
 * Sets the [[descendantOf]] property.
 *
 * @param int|ElementInterface|null $value The property value
 *
 * @return static self reference
 */
public function descendantOf($value);

You'll have to insert the ID of your accessories element or the element itself

{% accessories = craft.categories.title('accessories').first() %}
{% set categoryGroup = craft.categories.group('productTypes').descendantOf(accessories) %}
| improve this answer | |

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.