# List of Primary Tags

**URL:** <https://forum.ghost.org/t/list-of-primary-tags/28079>\
**Category:** Themes\
**Created:** [January 23, 2022, 8:17pm UTC](https://forum.ghost.org/t/list-of-primary-tags/28079 "2022-01-23T20:17:07Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![ahmadajmi](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/ahmadajmi/32/23173_2.png) [@ahmadajmi](https://forum.ghost.org/u/ahmadajmi)\
**Post date:** [January 26, 2022, 3:23pm UTC](https://forum.ghost.org/t/list-of-primary-tags/28079/3 "2022-01-26T15:23:11Z")

</div>

This is a workaround.

1. Loop through posts
2. Loop through tags for each post. Limit the tags to one, which will be the primary tag.

```auto
{{#get 'posts' include='tags'}}
  {{#foreach posts}}
    {{#foreach tags limit='1'}}
    <li class='item' data-slug='{{slug}}'>
      <a href='{{ url }}'>{{ name }}</a>
    </li>
    {{/foreach}}
  {{/foreach}}
{{/get}}

```

1. All the primary tags will be now visible but with duplication. With some JS, you can clean the duplicated ones.

```auto
<script>
$(document).ready(function() {
  var found = {};
  $('.item').each(function() {
    var $this = $(this);
    if(found[$this.attr('data-slug')]) {
      $this.remove();
    } else {
      found[$this.attr('data-slug')] = true;
    }
  });
});
</script>

```

Make sure jQuery is loaded before that JS code. _JS code credit: [https://mijokristo.com/remove-duplicate-elements-from-list-by-value-with-jquery/](https://mijokristo.com/remove-duplicate-elements-from-list-by-value-with-jquery/)_

_Update (None jQuery Code):_

```auto
<script>
  var finalList = { },
      elements = document.querySelectorAll('.item');

  elements.forEach( element => {
    if (finalList[element.dataset.slug]) {
      element.style.display= 'none';
    } else {
      finalList[element.dataset.slug] = true;
    }
  });
</script>

```

---

_[View the full topic](https://forum.ghost.org/t/list-of-primary-tags/28079)._
