Skip to content

Show List of Primary Tags in Ghost

I came across this Ghost Forum post about showing a list of primary tags. There is no native Ghost helper, but here is a workaround.

Loop through posts. Then, loop through tags for each post and limit the tags to one, which will be the primary tag.

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

All the primary tags will now be visible but with duplication. With some JavaScript, we can clean the duplicated ones.

  var finalList = { },
      elements = document.querySelectorAll('.item');

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

jQuery version.

Make sure to load jQuery before that JS code.

$(document).ready(function() {
  var found = {};
  $('.item').each(function() {
    var $this = $(this);
    if(found[$this.attr('data-slug')]) {
    } else {
      found[$this.attr('data-slug')] = true;

JS code credit:

Hopefully, you find this helpful.


Latest Ghost Themes

Use code TODAY for 10% off