How To Exclude Specific Posts from the Home Page

Step 1: In the ghost admin, Tags, add a new Internal Tag #noindex. You will add this tag to any post or page that you want to exclude from appearing on the home page.

Step 2: In the Casper theme, in the index.hbs, edit the following code in between {{#foreach posts}} and {{/foreach}} like this…

        {{#foreach posts}}


            {{!-- exclude #noindex --}}
            {{#has tag="#noindex"}}
                {{!-- nothing --}}
            {{else}}
            {{!-- The tag below includes the markup for each post - partials/post-card.hbs --}}
            {{> "post-card"}}
            {{/has}}


        {{/foreach}}

So the Main Content Area section should now look like this:

{{!-- The main content area --}}
<main id="site-main" class="site-main outer">
<div class="inner posts">

    <div class="post-feed">
        {{#foreach posts}}


            {{!-- exclude #noindex --}}
            {{#has tag="#noindex"}}
                {{!-- nothing --}}
            {{else}}
            {{!-- The tag below includes the markup for each post - partials/post-card.hbs --}}
            {{> "post-card"}}
            {{/has}}


        {{/foreach}}
    </div>

</div>
</main>

I lifted this code from…

1 Like

For your specific use case, you should be able to simply use {{^has tag="#noindex"}} to select posts without the internal tag =)

1 Like

Hey @itsmingjie thank you for that!

I’ve been posting more on this forum over the holidays, and it’s been pretty quiet.

I was beginning to wonder if this REALLY WAS a “ghost” forum (like an abandoned “ghost ship” spookily adrift on the sea.)

So here’s how I applied that in my index.hbs…

{{#foreach posts}}

    {{!-- Exclude posts tagged #noindex --}}
    {{^has tag="#noindex"}}

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

{{/foreach}}

1 Like