Hide specific articles tagged with a specific tag

I want to keep separated the newsletters from the articles I write in public. The idea is to send newsletters as a compilation of my articles so it’s meaningful to list them as articles in the homepage and other tag pages. I can tag the newsletters with a private tag but I don’t know how to filter them.

Any ideas?

2 Likes

You can use post settings to set post visibility (public, free, paying members) or you can use an internal tag (#tag) to filter out post from a collection

I think you can achieve that with the right routes.yaml config.

I have similar setup that shows all articles on the homepage except one tag. Articles from that one tag are available only from its tag page (homepage, tag page).

Check out my routes.yaml configuration.

Hope that helps.

If you’re using {{#get}} to list your articles you may want try {{#if primary_tag.your_tag}} – https://ghost.org/changelog/primary-tags/

Alternatively, you can use {{#has tag=“your_tag”}} … {else}} {{/has}} – https://ghost.org/docs/themes/helpers/has/

Hope it helps!

Yes, you are right. this is the way to do this.
First I created a public tag and then in the routes.yaml I added a filter to the / (root) collection with a. minus, so in the homepage I will not showing the posts tagged with this tag.

collections:
/:
permalink: /{slug}/
template: index
filter: tag:-tagiwanttofilter

And after that I created a new collection to create a special URL for this tag creating a new collection so all the posts tagged with this specific tag will have a special URL:

  /tagiwanttofilter/:
permalink: /tagiwanttofilter/{slug}/
template: tag
filter: tag:tagiwanttofilter
data: tag.tagiwanttofilter

And it works perfectly fine. Hope it helps.

postdata: it would be fantastic if this work with a private tag as well, but for now it is OK.

If you want to use this with a private tag, you just have to check the slug from the Tag page in your admin. They are usually something like hash-tagiwanttofilter. So to exclude in the routes file, just use filter: tag:-hash-tagiwanttofilter instead of filter: tag:-hash-tagiwanttofilter

thank you @dan but putting “hash” before the tag name doesn’t work (I get a 404) and I don’t know why.
At the end the best output I can get right now is:

  • use a private tag instead of a public one
  • posts with the collection slug in the URL
  • page with the collection slug to list all the posts

To get this I had to remove the data parameter from the collection definition in the routes.yaml

The problem of this is that the page of the collection doesn’t get the meta data, canonical and code injection from the tag definition, so I don’t know how to customize this.