惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
DataBreaches.Net
IT之家
IT之家
The Cloudflare Blog
Apple Machine Learning Research
Apple Machine Learning Research
WordPress大学
WordPress大学
N
Netflix TechBlog - Medium
阮一峰的网络日志
阮一峰的网络日志
P
Proofpoint News Feed
L
LangChain Blog
博客园 - Franky
美团技术团队
J
Java Code Geeks
Microsoft Security Blog
Microsoft Security Blog
博客园 - 叶小钗
小众软件
小众软件
Y
Y Combinator Blog
B
Blog RSS Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
D
Docker
Hugging Face - Blog
Hugging Face - Blog
Jina AI
Jina AI
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
Vercel News
Vercel News

Example blog

Ghost routing explained with routes.yaml examples — routes, collections & taxonomies Ghost redirects explained with practical redirects.yaml examples How to Serve JSON or XML Data in Ghost How to Change Your Default Post Template in Ghost Ghost Custom Theme Settings How to add Google Fonts to Ghost Themes How to Configure Ghost with Mailgun Ghost Theme Structure & Organization How to Make Custom Templates in Ghost Themes How to Install Ghost CMS via Ghost-CLI How to Add Syntax Highlighting to Ghost The best Ghost CMS hosting platforms Ghost 6.0 — Social Web and Native Ghost Analytics Ghost CMS Social web beta, email 2FA and more author social links How to keep custom design settings when updating your Ghost theme How to use the public preview card in Ghost How to add members-specific sections in Ghost How to customize the default content CTA in Ghost How to build a custom homepage in Ghost An overview of Ghost editor cards and and how they work Ghost CMS News: One-time payments & collecting sales tax How to customize the private site access template in Ghost How to add custom fonts in Ghost themes Ghost CMS News: Additional payment methods & internal linking How to use Code Injection in Ghost How to set meta data of your custom routes & collections in Ghost Ghost CMS News: TK reminders, ActivityPub and improvements How to format dates and use the date helper in Ghost Ghost CMS internationalization, custom fonts & spam protection Understanding and optimizing post and page settings in Ghost CMS
How to Hide a Post From the Home Page in Ghost CMS
Bright Themes · 2023-07-25 · via Example blog

Most Ghost themes will show the latest posts on your home page by default, but there are a number of reasons you might want to hide certain posts.

Whether some posts are intended to be sent just as a newsletter, or you have a different layout in mind for the home page, or simply there is no need for the post to appear on the home page.

Whatever the reason, you can hide a post on the homepage of your Ghost site in a few easy steps. Let’s look at the different options you have to achieve this.

Hide posts using the routes file

The easiest option is to add a filter in the routes.yaml file. (Learn more about routing and the routes.yaml file).

The part we need to change is the main collection:

collections:
  /:
    permalink: /{slug}/
    template: index
    filter: tags:-hash-hide

The important part here is the filter property. In this case, we are excluding every post from the main collection that has the internal tag #hide. Any post that has this tag, will not appear on the home page anymore.

Of course, this is just an example and you could use any tag for this, maybe in your case, it makes more sense to have #newsletteror #hidden.

Note

You can apply the same filter for channels as well.

For example:

channels:
  /blog/:
    permalink: /blog/{slug}/
    template: blog
    filter: tags:-hash-hide
  /portfolio/:
    permalink: /portfolio/{slug}/
    template: portfolio
    filter: tags:-hash-hide

Hide posts modifying the theme files

Another option to achieve this is modifying your theme files.

For the home page that is usually index.hbs, where you usually have a section where you loop over the posts, and you can check for a specific tag.

{{#foreach posts}}
	{{^has tag="#hide"}}
	  {{!-- you post card probably --}}
	{{/has}}
{{/foreach}}

The {{#has}} checks if the post has the #hide tag. {{#has}} is like {{#if}} but with the ability to do more than test a boolean. It allows theme developers to ask questions about the current context and provide more flexibility for creating different layouts.

Like all block helpers, {{#has}} supports adding an {{else}} block or using ^ instead of # for negation.

If it's needed you can also implement this change in the author.hbs and tag.hbs templates as well.

Hide posts using CSS

A third option is using CSS, but this depends on your theme. In the usual case, inside a {{#foreach}} there is a .post-card and the {{post_class}} outputs all the tags assigned to that post.

To hide post with the #hide tag you can add the following in Code Injection:

<style>
  .post-card.tag-hash-hide {
    display: none;
  }
</style>

The drawback of this solution is that the post can still be found in the source code.

In the end, all of this will work. I hope you find it useful.