1

We have a client that has a good deal of products in one channel. We're categorizing each product entry with a pretty extensive category tree. The reason we didn't go with a structure is because many products needed to exist in multiple categories and a structure tree would get messy.

Everything is working great, but they now want to be able to re-order entries by category in the CP and we're sort of stuck. The new Category Sources plugin sort of gets us half way there but it doesn't allow you to reorder and save the order in any way.

Anyone run into this sort of issue? Thanks.

  • Where are you trying to reorder, in the CP or somewhere on the frontend in a list? – Aaron Berkowitz Feb 18 '15 at 16:35
  • Ideally in the CP, but open to other ideas. – Vince Feb 18 '15 at 16:39
  • What do you mean with "by category" for each category an entry is assigned to or is there one (main) category responsible for the listing? – carlcs Feb 18 '15 at 17:07
  • Multiple categories responsible for the listings. We have a nav on the front end that is built from the category taxonomy, and then each sub category link pulls up a page that lists products attached to that category. – Vince Feb 18 '15 at 17:22
  • So this means you have to sort an entry multiple times, within each category it is listed in. – carlcs Feb 18 '15 at 17:32
3

If you reverse the relationship then you should be able to order the entries (i.e. add products to an entries field within the category, instead of adding categories to a categories field within the product).

So instead of grabbing the products using relatedTo(category),

{% set products = craft.entries.section('products').relatedTo(category) %}
{% for product in products %}...{% endfor %}

you would be able to grab the products directly from the products entries field in the category using category.productsFieldHandle, which should be returned in the order defined in the CP.

{% set products = category.productsEntriesFieldHandle %}
{% for product in products %}...{% endfor %}
  • Ahhh, this may actually work. Can't believe we didn't think about this. We'd have to do some work, but not nearly as bad as moving the whole thing to a structure. Thanks so much! – Vince Feb 18 '15 at 19:47

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.