<p>You can do this in the CP by default.</p>

<p>If you have a category field "categories", the user can select one or more categories and then drag them into the order they want.</p>

<p>On the frontend you just loop over them like this to show them in the order they selected.</p>

<pre><code>{% for category in entry.categories %}
    &lt;a href="{{ category.url }}"&gt;{{ category.title }}&lt;/a&gt;
{% endfor %}
</code></pre>

<p>Same goes if you want to just show all categories from a category group, you can drag and drop them in the CP and then print them out in your code.</p>

<pre><code>{% for category in craft.categories.group('cats') %}
    &lt;a href="{{ category.url }}"&gt;{{ category.title }}&lt;/a&gt;
{% endfor %}
</code></pre>

CC BY-SA 3.0
2017-10-17T21:10:36.180Z
This doesn't appear to be the case, unfortunately: https://craftcms.stackexchange.com/questions/19308/custom-category-order-in-a-categories-field?rq=1 More specifically: the comment about ordering Categories attached to another element does not represent an actual option within the Craft Admin. In the past, if this has been a requirement, I've just made the _Category Group_ a _Section_, and used _Entries_ as the relational object. As far as I can tell, there isn't a fundamental, functional, or performance difference between relating _Entries_ via other _Entries_ vs. via _Categories_.
August Miller
CC BY-SA 3.0
2017-10-17T21:13:09.630Z
Of course, Categories _can_ by organized in their Category Group hierarchy view. Just make sure you've selected "Structure" from the sorting drop-down, and they'll be sortable!
August Miller
CC BY-SA 3.0
2017-10-17T18:40:35.730Z
2017-10-17T18:40:35.730Z
Syversen
<p>I ended up finding this code snipped, which worked for me:</p>

<p><a href="https://gist.github.com/zackspear/7cdd656f9bb34e210676" rel="nofollow noreferrer">https://gist.github.com/zackspear/7cdd656f9bb34e210676</a></p>

CC BY-SA 3.0
2017-10-17T18:34:33.500Z
2017-10-17T18:34:33.500Z
Molly Harper
<p>I'd like to set a user defined order for a Categories field. For example, categories are:</p>

<p>Cat A
Cat B
Cat C</p>

<p>I'd like to give the ability for users to drag and drop the order, to say:</p>

<p>Cat B
Cat A
Cat C</p>

<p>What is the best way to handle this?</p>

<categories>
User defined order for categories
# User defined order for categories

(Asked by: username_0 on 2017-10-17)

I'd like to set a user defined order for a Categories field. For example, categories are:

Cat A
Cat B
Cat C

I'd like to give the ability for users to drag and drop the order, to say:

Cat B
Cat A
Cat C

What is the best way to handle this?

**Tags:** categories


---

## 2 answers

### Answer by username_1 on 2017-10-17. Score: 1

You can do this in the CP by default.
If you have a category field "categories", the user can select one or more categories and then drag them into the order they want.
On the frontend you just loop over them like this to show them in the order they selected.
{% for category in entry.categories %}
    {{ category.title }}
{% endfor %}

Same goes if you want to just show all categories from a category group, you can drag and drop them in the CP and then print them out in your code.
{% for category in craft.categories.group('cats') %}
    {{ category.title }}
{% endfor %}

> **Comments:**
> **username_2**: This doesn't appear to be the case, unfortunately: https://craftcms.stackexchange.com/questions/19308/custom-category-order-in-a-categories-field?rq=1 More specifically: the comment about ordering Categories attached to another element does not represent an actual option within the Craft Admin. In the past, if this has been a requirement, I've just made the _Category Group_ a _Section_, and used _Entries_ as the relational object. As far as I can tell, there isn't a fundamental, functional, or performance difference between relating _Entries_ via other _Entries_ vs. via _Categories_.  
> **username_2**: Of course, Categories _can_ by organized in their Category Group hierarchy view. Just make sure you've selected "Structure" from the sorting drop-down, and they'll be sortable!  

---

### Answer by username_0 on 2017-10-17. Score: 0

I ended up finding this code snipped, which worked for me:

<https://gist.github.com/zackspear/7cdd656f9bb34e210676>


---

