How to Exclude Tags from The Tag List in Ghost Theme

by ElectronThemes in Ghost on January 20, 2019

Sometimes we make a tag list in Ghost Theme. We may want to show all tags or we may not. Now I will show how to show all tags and how to exclude some specific tags from the tag list.

Showing all tags on a specific page

For showing all tags, we need to use Get helper in the code. Firstly make sure that your public API is active. If public API of Ghost is active, you can follow the code.

{{#get "tags" include="count.posts"}}
    {{#foreach tags}}
        <img src="{{cover_image}}"> {{!-- For tag cover image --}}
        <h4>{{name}}</h4> {{!-- For tag name --}}
        <p>{{description}}</p> {{!-- For tag description --}}
        {{plural count.posts empty="no article" singular="1 article" plural="% articles"}} {{!-- For counting posts under this tag --}}
        <a href="{{url}}">Read More</a> {{!-- For tag url --}}

Using this code, you can show all tags on a page. You can use this list of attributes.

List of Attributes

  • id – the incremental ID of the tag
  • name – the name of the tag
  • slug – slugified version of the name (used in urls and also useful for class names)
  • description – a description of the tag
  • feature_image – the cover image for the tag
  • meta_title – the tag’s meta title
  • meta_description – the tag’s meta description
  • url – the web address for the tag’s page

Exclude specific tag from taglist

If you don’t want to show all tags on the taglist, you can easily exclude the tag from the taglist. I will show you now show to exclude the specific tags.

{{#get "tags" filter="slug:-life"}}
    {{#foreach tags}}
        <a href="{{url}}">{{name}}</a>

It will exclude the life tag automatically from all the other tags of the theme. If you want to exclude two or more tags, you have use array  [] notation. You can use like this.

{{#get "tags" filter="slug:-[life, child, getting-started]"}}
    {{#foreach tags}}
        <a href="{{url}}">{{name}}</a>

I hope this article will help you to exclude specific tag from the tag list.

You can see our latest themes from here