<p>I managed to solve this by defining the tags as a ElementCriteriaModel. Instead of using the code above I used the following:</p>

<pre><code>{% set tags = entry.tagsFieldHandle %}

{% if tags | length %}
   {% for tag in tags %}
      &lt;li&gt;{{ tag }}&lt;/li&gt;
   {% endfor %}
{% endif %}
</code></pre>

<p>Explained further in the <a href="http://buildwithcraft.com/docs/tags-fields#templating" rel="nofollow">Tag section in the docs</a>. <code>{% set tags = entry.tagsFieldHandle %}</code> is a shortcut for:</p>

<pre><code>{% set tags = craft.tags({
   relatedTo: { sourceElement: entry, field: "tagsFieldHandle" },
   order:     "sortOrder",
   limit:     null
}) %}
</code></pre>

<p>This meant I didn't need to define the entry relation as the model does that be default and it also sorted the tags as they were defined in the entry with the "sortOrder" (which is also default).</p>

CC BY-SA 3.0
2015-10-07T03:29:45.423Z
Thank you for posting this solution. I was needing this exactly thing.
Anna_MediaGirl
CC BY-SA 3.0
2015-10-07T08:56:11.853Z
You're welcome, I'm glad it helped
JRW
CC BY-SA 3.0
2015-09-22T11:02:13.577Z
2015-09-22T11:02:13.577Z
JRW
<p>Is it possible to output tags for an entry page in the order they were added to related entry?</p>

<p>For example on a News page I would like to output any/all tags added to the News article on the specific article page in the order the tags were added to that article, I currently output the tags using the following:</p>

<pre><code>        {% for tag in craft.tags.relatedTo(entry) %}
            &lt;li&gt;{{ tag }}&lt;/li&gt;
        {% endfor %}
</code></pre>

<p>This works great as it only outputs the tags that have been added to that entry, but it shows the tags in the default title ascending order rather than reflecting the order on the entry.</p>

<p>I can switch the order by setting it to desc on the title <code>.order('title desc')</code> and I've also read through the docs on <a href="http://buildwithcraft.com/docs/templating/craft.tags#order" rel="nofollow">ordering</a> but I'm still not sure how to achieve this.</p>

<p>Thanks,</p>

CC BY-SA 3.0
2015-09-22T04:43:50.310Z
Have you tried using `fixedOrder`? I'm not sure how you would know the id's of the tags that are getting used for any given entry though...
Damon
CC BY-SA 3.0
2015-09-22T06:47:23.730Z
Yep, but no luck. I managed to solve it using 'sortOrder'. I'll post my code later in case anyone else is trying the same thing
JRW
CC BY-SA 3.0
2015-09-22T10:46:24.610Z
Awesome! Please do!
Damon
<entry><tags><ordering><order>
Output tags in the order they were added to an entry
# Output tags in the order they were added to an entry

(Asked by: username_0 on 2015-09-20)

Is it possible to output tags for an entry page in the order they were added to related entry?
For example on a News page I would like to output any/all tags added to the News article on the specific article page in the order the tags were added to that article, I currently output the tags using the following:
        {% for tag in craft.tags.relatedTo(entry) %}
            {{ tag }}
        {% endfor %}

This works great as it only outputs the tags that have been added to that entry, but it shows the tags in the default title ascending order rather than reflecting the order on the entry.
I can switch the order by setting it to desc on the title .order('title desc') and I've also read through the docs on ordering but I'm still not sure how to achieve this.
Thanks,

**Tags:** entry, tags, ordering, order

> **Comments:**
> **username_1**: Have you tried using `fixedOrder`? I'm not sure how you would know the id's of the tags that are getting used for any given entry though...  
> **username_0**: Yep, but no luck. I managed to solve it using 'sortOrder'. I'll post my code later in case anyone else is trying the same thing  
> **username_1**: Awesome! Please do!  

---

## 1 answers

### Answer by username_0 on 2015-09-22. Score: 1 | Accepted answer

I managed to solve this by defining the tags as a ElementCriteriaModel. Instead of using the code above I used the following:
{% set tags = entry.tagsFieldHandle %}

{% if tags | length %}
   {% for tag in tags %}
      {{ tag }}
   {% endfor %}
{% endif %}

Explained further in the Tag section in the docs. {% set tags = entry.tagsFieldHandle %} is a shortcut for:
{% set tags = craft.tags({
   relatedTo: { sourceElement: entry, field: "tagsFieldHandle" },
   order:     "sortOrder",
   limit:     null
}) %}

This meant I didn't need to define the entry relation as the model does that be default and it also sorted the tags as they were defined in the entry with the "sortOrder" (which is also default).

> **Comments:**
> **username_2**: Thank you for posting this solution. I was needing this exactly thing.  
> **username_0**: You're welcome, I'm glad it helped  

---

