Just a short blog post today where I quickly go through something I had to figure out today.

I've been busy setting up my website to include more information about my previous employment and freelance work which I've been doing by using posts. The trouble is, I didn't want these posts suddenly clogging up my homepage.

I managed to get around this by editing the index.hbs file to filter through the posts returned for the homepage and then excluding certain tags. In my case, I wanted to get rid of any posts which had the Portfolio or Freelance-Portfolio tags.

To do this, I opened up: /var/www/ghost/content/themes/[THEME TEMPLATE]/index.hbs and found the line where it includes the following block of code:

{{#foreach posts}}
{{!-- The tag below includes the markup for each post - partials/post-card.hbs --}}
   {{> "post-card"}}
{{/foreach}}

All we need to do is wrap this foreach in a #get filter to exclude out any of my chosen tags. Typically, this GET filter is mainly used for including posts with a certain combination of tags but it can be reversed by including a minus sign (-) as I've done below. You can see more about the options available in the filter by heading to the Ghost API docs.

{{#get "posts" filter="-[tag-1, tag-2]"}}{{/get}}

This process works the same way if you want to exclude one, or multiple tags from your homepage. So, now that block of code should look like:

{{#get "posts" filter="tags:-[Freelance-Portfolio,Portfolio]"}}
{{#foreach posts}}
{{!-- The tag below includes the markup for each post - partials/post-card.hbs --}}
   {{> "post-card"}}
{{/foreach}}
{{/get}}

Now, when I load up the homepage, I can see all of my previous posts but any using the Portfolio or Freelance-Portfolio tags have been excluded and I don't have portfolio examples cluttering up the homepage.

Hope this was useful!