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

推荐订阅源

T
The Exploit Database - CXSecurity.com
V
Vulnerabilities – Threatpost
Google DeepMind News
Google DeepMind News
Attack and Defense Labs
Attack and Defense Labs
Webroot Blog
Webroot Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
TaoSecurity Blog
TaoSecurity Blog
I
Intezer
Application and Cybersecurity Blog
Application and Cybersecurity Blog
N
News | PayPal Newsroom
S
Security Affairs
T
Tor Project blog
P
Proofpoint News Feed
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Security @ Cisco Blogs
H
Heimdal Security Blog
Hacker News: Ask HN
Hacker News: Ask HN
Help Net Security
Help Net Security
U
Unit 42
云风的 BLOG
云风的 BLOG
The Hacker News
The Hacker News
Cisco Talos Blog
Cisco Talos Blog
量子位
F
Full Disclosure
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 叶小钗
有赞技术团队
有赞技术团队
T
Troy Hunt's Blog
P
Privacy & Cybersecurity Law Blog
Forbes - Security
Forbes - Security
人人都是产品经理
人人都是产品经理
L
Lohrmann on Cybersecurity
Apple Machine Learning Research
Apple Machine Learning Research
Microsoft Security Blog
Microsoft Security Blog
博客园 - Franky
腾讯CDC
AI
AI
Last Week in AI
Last Week in AI
Latest news
Latest news
Google Online Security Blog
Google Online Security Blog
N
Netflix TechBlog - Medium
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
IT之家
IT之家
Martin Fowler
Martin Fowler
Blog — PlanetScale
Blog — PlanetScale
V2EX - 技术
V2EX - 技术
酷 壳 – CoolShell
酷 壳 – CoolShell

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 Trigger the Ghost Portal popup based on page scroll progress How to Deploy Your Ghost Theme with GitHub Actions How to create a custom recommendations page for your Ghost CMS theme Ghost CMS News: New editor, refreshed settings & recommendations Ghost CMS News: Source - the new default theme and native image editing How to Add Different Logos for Dark & Light Themes in Ghost Upgrade to Node v18 for Ghost CMS & common errors Ghost Snippets: Adding Schema markup in Ghost How to add a scroll-based progress bar to your Ghost CMS site How to Create a Custom Navigation Template in Ghost How to Segment Subscribers with Member Labels in Ghost The best way to create a contact page in Ghost How to Use the Ghost Subscription Forms in Your Theme & Posts How to update your Ghost site URL when self-hosting Ghost CMS News: Signup cards and better landing pages How to Add Breadcrumbs to Your Ghost Theme How to integrate the Applause Button into your Ghost theme How to Hide a Post From the Home Page in Ghost CMS Ghost CMS block and contentFor helper overview & tips How to add Image Lightbox to Ghost Themes Ghost CMS News: Signup form embed, new editor and bulk actions. Biron Themes becomes Bright Themes 🎉 How to Audit & Test a Ghost Theme How to Use Ghost Filter Expressions Ghost CMS newsletter settings and post analytics How to Update Your Ghost Theme When We Release New Versions Ghost CMS News: Automatic list cleaning & email troubleshooting How to Create a Featured Post Slider in Ghost How to Add Reading Time to Ghost Blog Posts How to Create a Post Archive for Your Ghost Theme Ghost CMS Price Helper Overview & Tips Self-Hosted Ghost CMS with DigitalOcean Ghost CMS News: Member Growth Sources & Audience Feedback How to Open External Links in a New Tab in Ghost How to Integrate Google Analytics with Ghost Ghost CMS News: History Log & Newsletter Analytics How to Automatically Add Member Labels From Referral Traffic in Ghost? Ghost CMS News: Free trials & email notifications Ghost CMS Match Helper Usage & Tips Ghost CMS News: Native Comments Ghost CMS News: Ghost Explore & Premium Newsletter Previews Ghost Snippets: Custom Progress Cards & Steps Ghost CMS News: Native Search The Best Ghost CMS Search Plugins & Libraries Ghost Snippets: Custom Stylish Tables How to Add a Scroll Top & Progress Indicator Button in Ghost Ghost Snippets: Accordions How to Add Tag Dropdown to Your Ghost Theme Ghost 5.0 released 🎉 Ghost Snippets: Custom Subscribe Forms Ghost Snippets: Custom Alert Boxes How to Show Post or Newsletter Issue Number in Ghost How to Self-Host Google Fonts in Ghost CMS Ghost CMS News: Membership, Tiers & Activity Feed Custom Pages in Ghost CMS Themes Ghost CMS Search Using Fuse.js Ghost CMS News: Offers and Discounts & New Cards Ghost CMS News: Membership tiers, email CTA & filters Ghost CMS News: Grammarly Support & Feature Image Captions. Ghost CMS News: Improved Member Accounts & Personalized Newsletter. Ghost 4.0 Launched With Native Newsletters & Membership Ghost CMS News: Cancellation Feedback & Newsletter Stats. Ghost CMS News: Improved Member Dashboard & Sidebar Views. Ghost CMS News: Google Pay support, email newsletters & secondary navigation Ghost CMS News: Member Support, Portal & Content Snippets. Ghost CMS News: Referral Programs & Responsive Images. Ghost Themes as Progressive Web Apps Ghost 3.0 is here with brand new features Ghost 2.0 is here with new features How to Add Search to Ghost Using ghostHunter
How to Create Related Posts Section in Ghost
Bright Themes · 2023-06-02 · via Example blog

A related posts, or a read next section is an essential component of any blog or website that aims to increase user engagement and provide a seamless browsing experience. By offering visitors relevant content based on their interests, you can extend their time on your site.

In this blog post, we will delve into the process of creating a related posts section in Ghost, but first let's discuss about the benefits.

Some of the key advantages include:

  1. Improved user experience: By suggesting relevant content, you enhance the browsing experience, making it easier for visitors to discover and access articles of interest.

  2. Increased engagement: Encouraging readers to explore more content can lead to longer session durations, decreased bounce rates, and a higher likelihood of conversion or interaction.

  3. Enhanced SEO: A well-implemented related posts section can contribute to improved search engine optimization by increasing the number of internal links and reducing the likelihood of orphaned pages.

  4. Cross-promotion: Utilize the related posts section to highlight older or lesser-known articles, giving them increased visibility and potentially driving traffic to older posts.

Now that we have an understanding of the benefits, let's delve into the technical part.

Identify where to implement the changes

To create a related posts section in Ghost, you'll need to make some modifications to your theme. Before making any changes, it's a good idea to create a backup of your theme to ensure you can revert to the original version if needed.

In general, in Ghost themes the post.hbs is responsible for rendering individual blog posts, locate the theme folder you are currently using and find the post.hbs file.

Within the file, you will see the opening and closing {{post}} tags, which gives us the context:

{{#post}}

  // your post layout here

{{/post}}

All the necessary changes for the related section can be done in this file.

Now that we have the place, let's get to the code part. Ghost provides a powerful Content API that allows you to fetch related posts based on various criteria, such as tags.

Ghost uses the Handlebars templating engine, so you can use its helpers and filters to filter and sort the posts.

You have two main options to get related posts:

  1. Based on the primary tag of your posts
  2. Based on all associated tags

In both cases we will be using the {{get}} helper.

If you are only interested in the primary tag (the first tag assigned to your posts), then you can use the following code inside the {{#post}} {{/post}} context:

{{#get
  'posts'
  include='tags,authors'
  limit='3'
  filter='id:-{{id}}+tag:[{{primary_tag.slug}}]'
}}

  <!-- Display related post details here -->

{{/get}}

As you can see in the code above, we are using some specific filters:

  • id:-{{id}} - to exclude the current post
  • tag:[{{primary_tag.slug}}] - to fetch posts that have the current posts' primary tag

It's also possible to get related posts for all tags that are associated with a post. For this add the following code after the closing {{/post}} tag:

{{#get
  'posts'
  include='tags,authors'
  limit='3'
  filter='id:-{{post.id}}+tags:[{{post.tags}}]'
}}

  <!-- Display related post details here -->

{{/get}}

As you can see, there are some minor differences compared to the precious code, this is because of the context:

  • id:-{{post.id}} - to exclude the current post
  • tags:[{{post.tags}}] - to fetch posts using all tags from the current post

Note

Use the limit property to change the maximum amount of posts that are fetched. Use the include property to add more context to the fetched posts.

Now that we have the data (posts) available, we can go on and display it. This can be done by adding HTML markup and CSS styling. In most themes there is a partial to render post cards in a specific way.

In our case, this is partials/post-card.hbs, assuming you have something similar, we can render the posts using this partial, by adding the following code inside the our previously defined {{get}}:

<section class="related-section">
  <h2 class="related-title">{{t "Read next"}}</h2>

  <div class="related-posts">

    {{#foreach related}}
      {{> post-card}}
    {{/foreach}}

  </div>
</section>

Within the {{#foreach posts}} block, you have each posts' details, which will be used to display various information about the post, for example, you can display the post title, excerpt, and a link to the post.

In our case what information is displayed is defined in the {{> post-card}} partial (partials/post-card.hbs).

To give you a complete example, for fetching 3 related posts based on the primary tag:

{{#get "posts" include="tags,authors" limit="3" filter="id:-{{id}}+tag:[{{primary_tag.slug}}]"}}

  <section class="related-section">
    <h2 class="related-title">{{t "Read next"}}</h2>

    <div class="related-posts">

      {{#foreach related}}
        {{> post-card}}
      {{/foreach}}

    </div>
  </section>

{{/get}}

In this guide we won't cover the styling, as that is specific to each theme, and in most cases the you can reuse class names to match the style of your current theme.

After following these steps, your Ghost CMS should display a related posts section on individual blog posts, showing posts that are related based on the criteria you defined.

Conclusions

By adding a related posts section to your Ghost blog, you can significantly enhance user engagement, improve the browsing experience, and drive more traffic to your content.

Follow the steps outlined in this guide to seamlessly integrate this feature into your Ghost theme and create a dynamic and engaging environment that keeps visitors exploring your content and coming back for more.