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

推荐订阅源

博客园 - 叶小钗
爱范儿
爱范儿
WordPress大学
WordPress大学
Last Week in AI
Last Week in AI
博客园 - 聂微东
雷峰网
雷峰网
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 三生石上(FineUI控件)
T
Tailwind CSS Blog
博客园 - Franky
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园_首页
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 司徒正美
月光博客
月光博客
大猫的无限游戏
大猫的无限游戏
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Cloudflare Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
人人都是产品经理
人人都是产品经理
宝玉的分享
宝玉的分享
罗磊的独立博客
Jina AI
Jina AI

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 create a custom recommendations page for your Ghos...
Bright Themes · 2024-01-12 · via Example blog

With the release of version 5.71.0 Ghost added the recommendations feature, publishers can share their favorite sites with their readers and, likewise, be recommended by other publications. Unlike some other platforms Ghost's recommendations system is built to be compatible with any platform, website, or publisher, so you can recommend whoever you like.

How Ghost's recommendations work?

Under the hood, Ghost's recommendations feature is built on the Webmention open standard, which means recommendations aren't limited to any single platform — but extend to every site on the web.

Recommendations also make it possible for readers to subscribe to recommended publications with a single click. This feature is currently exclusive to Ghost sites, but it's possibly going to be possible to integrate it with other platforms too.

Here are some key things happening:

  1. In Ghost, the recommendations modal is shown automatically whenever a new member subscribes to a Ghost publication. You can see the modal using the link: https://yoursite.com/#/portal/recommendations
  2. Adding a recommendation will trigger a check to see if the recommended site has Webmentions enabled. Ghost only notifies sites about your recommendation if they have a Webmention endpoint that can receive it.
  3. Your site receives recommendations in the same way as described above but as the recipient. Ghost automatically adds a link tag to your publication to inform other sites about your Webmention endpoint. Once the incoming recommendation is verified, it's added to Ghost Admin and you receive a notification.

Built-in recommendations

Ghost comes with all the tools to manage and show your recommendations, you don't have to add anything to your Ghost theme for this.

You can mange your recommendations in the Ghost Admin > Settings > Recommendations (#/settings/recommendations).

You have two tabs:

  • Your recommendations - listing all the sites you have recommended, including the number of clicks each has received
  • Recommending you - list of sites and publications recommending your site

There is also a button to Add recommendation, where you have to provide the URL of the site you want to recommend, any website not just those published on Ghost.

Ghost recommendation settings
Ghost recommendation settings

Additionally, the Ghost Portal was extended to include recommendations, here's the link to access it: #/portal/recommendations

Recommendations in Ghost themes

Recommendations can also be natively integrated into any Ghost theme, for this two new helpers were introduced: {{recommendations}} and {{readable_url}}.

Recommendations helper

The {{recommendations}} helper can be used anywhere in your theme and it will output a list of recommended sites based on the default template provided by Ghost.

Alternatively, you can override the default template altogether with a custom one by adding a file called recommendations.hbs to the theme's /partials/ folder.

The recommendations helper accepts the following attributes:

  • limit - set the maximum number of recommendations to display, the default is 5.
  • order - set the order of recommendations based on any valid resource field, the default order is newest first ()created_at desc)
  • page - when the total number of recommendations exceeds the number defined in limit, recommendations become paginated
  • filter - use logic-based queries to filter recommendations

For more details, check out the official documentation.

Readable url helper

The {{readable_url}} helper outputs a human-readable URL. While this helper was created for the output of recommended sites, it can be used anywhere else where you need it.

What the helper does:

  • removes the protocol (https://)
  • removes www
  • removes query parameters
  • removes hash fragments

It doesn't remove any subdomains or pathnames.

The {{recommendations}} and {{readable_url}} helpers all you need to create your own recommendations section or page.

Custom recommendations page

To create a custom recommendations page, we have to create a custom template with code for rendering recommended sites, assign the template to a route, styling the list. Now let's see each of those in detail.

Create a custom template

Create a new file in the root directory of your theme, for example: recommend.hbs The template needs a few parts:

  • {{!< default>}} to inherit from your default template
  • a page title
  • the recommendations

Here's what the file would look like:

{{!< default}}

{{#page}}
  <h1 class="page-title">{{t "Recommendations"}}</h1>
{{/page}}

{{recommendations}}

This would render the recommendations using the default Ghost template, if you want to define your own markup and css classes create the recommendations.hbs file in the /partials/ directory.

Create the route

Now that the template is ready, we have to create a new route. For this we have to add a new entry in the routes.yaml file, under the routes: section:

  /recommendations/:
    template: recommend

This creates the /recommendations/ route and sets our recommend.hbs file as the template.

Note

If you are using Ghost locally, don't forget to restart Ghost.

Styling the recommendations

As mentioned already, you can overwrite the default recommendations template, in which case you can define your own CSS classes (ideal for something like Tailwind), this is what we did for the Bokeh theme, here's the demo.

If you are using the default Ghost template, there are a few CSS classes to target:

  • recommendations - the <ul> element class
  • recommendation - the <li> element class
  • recommendation-favicon - the favicon class (has in <img> inside)
  • recommendation-title - the title element class (<h5>)
  • recommendation-url - the url element class (<span>)
  • recommendation-description - the description element class (<p>)

You can integrate the styles in your theme's assets or alternatively add the them in Code Injection:

<style>
.recommendations {
  /* Add your styling for the recommendations list */
}

.recommendation {
  /* Styling for individual recommendation */
}

.recommendation-title {
  /* Styling for the recommendation title */
}

.recommendation-favicon {
  /* Styling for the recommendation favicon */
}

.recommendation-url {
  /* Styling for the recommendation url */
}

.recommendation-description {
  /* Styling for the recommendation description */
}
</style>

Styles are not included here, but you have all the steps to create a custom recommendations page.


In conclusion, the new recommendations feature in Ghost offers publishers a powerful tool to engage with readers and discover new sites. Recommendations extend beyond the Ghost platform, making it compatible with any website or publisher.

With easy management in Ghost Admin, integration into Ghost themes, and the possibility of custom recommendations pages, publishers have the flexibility to tailor the feature to their needs.

Whether you want to share your favorite sites or receive recommendations for your publication, Ghost's recommendations feature provides a seamless and efficient solution.