Filtering Tags via tag.hbs

And

  • How was Ghost installed and configured? Via Docker and the Docker hub image
  • What Node version, database, OS & browser are you using? TBC
  • What errors or information do you see in the console? None
  • What steps could someone else take to reproduce the issue you’re having?
    Add the following to your tag.hbs.

The issue is this…
I have certain posts I want to hide when I click on the associated tag.
Therefore Ive added a filter via ^has in tag.hbs. But this filters (removes the posts) but now when I go to the tag the output is not correct. Its hard to explain but you will see from here Suzieq - Packet Coders. The posts are hidden but the displayed posts are not displayed in the right places. In this example I have 1 post but it displays it on page 2.

Ive tried using a visibility on the foreach, but the same happens. Any ideas? Thanks

tag.hbs

...
   <div class="inner posts">
        <div class="post-feed">
            {{#foreach posts}}
		{{^has tag="#lesson"}}
		    {{!-- The tag below includes the markup for each post - partials/post-card.hbs --}}
			{{> "post-card"}}
		{{/has}}
            {{/foreach}}
        </div>
        {{pagination}}
    </div>
</main>
1 Like

I hope I understand your issue correctly.
You may want to add a custom get section enclosing the foreach loop and filter out the unwanted posts by tag there (you may need to set the proper slug for tag). Also set limit parameter to how many posts you want in a page(below gets it from package.json using @config, but you can set a fixed value)

   {{#get "posts" include="tags,authors" filter="tag:{{tag.slug}}+tag:-#lesson" limit=@config.posts_per_page page=pagination.page}}
            {{#foreach posts}}
               {{> "post-card"}}
            {{/foreach}}
            {{pagination}}
      {{/get}}

I tested this with Ease theme and it works as expected

Thanks for your response. I tried this and I get the expected filtering tags for the tag.slug. But the posts with the internal tag lesson are still shown (?). Thanks again for your help …

Have you checked the slug of the internal tag? I noticed Ghost converted #lesson to hash-lesson for me, so there may be a mismatch there

Great that works really well. THANK YOU!
The only thing I have noticed is that I get an empty 2nd page on each tag (?)

Example below:

I see some of the tags are showing this behavior, not all of them. Which theme are you using? I’d like to download&activate it myself and see what’s going on