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

推荐订阅源

aimingoo的专栏
aimingoo的专栏
Google DeepMind News
Google DeepMind News
S
SegmentFault 最新的问题
Project Zero
Project Zero
D
DataBreaches.Net
I
InfoQ
L
Lohrmann on Cybersecurity
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
酷 壳 – CoolShell
酷 壳 – CoolShell
Stack Overflow Blog
Stack Overflow Blog
The Register - Security
The Register - Security
Recorded Future
Recorded Future
Vercel News
Vercel News
博客园 - 司徒正美
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
I
Intezer
The Hacker News
The Hacker News
F
Fortinet All Blogs
Microsoft Azure Blog
Microsoft Azure Blog
P
Proofpoint News Feed
Help Net Security
Help Net Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Scott Helme
Scott Helme
T
Threatpost
爱范儿
爱范儿
N
Netflix TechBlog - Medium
D
Docker
云风的 BLOG
云风的 BLOG
C
Cisco Blogs
K
Kaspersky official blog
H
Help Net Security
S
Secure Thoughts
T
Threat Research - Cisco Blogs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
Security @ Cisco Blogs
Cyberwarzone
Cyberwarzone
N
News and Events Feed by Topic
G
Google Developers Blog
Forbes - Security
Forbes - Security
博客园 - 三生石上(FineUI控件)
博客园 - 叶小钗
B
Blog
Google DeepMind News
Google DeepMind News
Recent Announcements
Recent Announcements
Simon Willison's Weblog
Simon Willison's Weblog
S
Securelist
P
Privacy International News Feed
Spread Privacy
Spread Privacy
The Last Watchdog
The Last Watchdog

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 Create Related Posts Section in Ghost 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 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 a Post Archive for Your Ghost Theme
Bright Themes · 2023-01-15 · via Example blog

Many readers want to browse old posts or find posts that they read but don't have the link for anymore. Even though blogging favors "today", some older posts still offer value over longer periods of time and the best way to make such posts available is through an archives page. In this post I’ll explain how you can create an archive page for your Ghost Theme.

Some of the advantages of an archive page:

  • it can increase engagement and maintain a positive community around your content
  • it can boost the amount of time that people spend on your site
  • you can increase the number of page views on each article
  • more chances to convert visitors into subscribers and/or customers.

So let's start creating a archive.

The simple archive page

Create a new file in the root folder of your theme, call it page-archive.hbs, it's a good idea to start from your page.hbs file. What we need to start with is fetching the posts and that is very easy to do using the {{get}} and {{foreach}} helpers.

{{#get 'posts' limit='all' order='published_at desc'}}
  <article class='content-wrap'>
    {{#foreach posts visibility='all'}}
      <a href='{{url}}' class='archive-post'>
        <time
          datetime='{{date published_at format='YYYY-MM-DD'}}'
          class='archive-post__date'
        >
          {{date published_at format='DD MMM YYYY'}}
        </time>
        <h2 class='archive-post__title'>{{title}}</h2>
      </a>
    {{/foreach}}
  </article>
{{/get}}

Let's break it down, the first part is fetching the posts, limit="all" tells the API we need all the posts (if you do not specify a limit the default is from your package.json config.posts_per_page). We will put all posts within an article element, then loop through all the fetched posts using the {{foreach}} helper. The visibility="all" will make sure all posts are listed regardless if they are public, free or member posts. The next part is the layout of the archive posts, in this case a simple one, listing the date and title.

After you have uploaded your modified theme (or restarted your Ghost instance) and navigate to yoursite.com/archive you should see the list of posts.

While this works fine, if you have a lot of posts it might not be a good idea to fetch them all (especially if you want to display the image as well). So let's take a look at another approach.

The more advanced archive

In this case we will create a new file called archive.hbs in the root folder of the theme, then the next step is to add a few lines to our routes.yaml file. By default you should have the collections and taxonomies defined and now we will add a new section under the routes:

routes:
  /archive/:
    controller: channel
    template: archive

collections:
  /:
    permalink: /{slug}/
    template: index

taxonomies:
  tag: /tag/{slug}/
  author: /author/{slug}/

In the end the routes.yaml should look like above (of course depending on your site this could be different as you might have another setup). Upload the modified file through Ghost Admin > Labs clicking on Upload routes.yaml.

Now let's start modifying the archive.hbs file:

{{!< default}}

{{! Archive Page }}
<div class='wrapper container'>
  <h1 class='archive__title'>{{t 'Archive'}}</h1>
  <div class='archive__excerpt'>
    {{#get 'posts'}}
      {{t
        'Browse the complete archive of {total} posts.'
        total=pagination.total
      }}
    {{/get}}
  </div>

  <div class='content'>
    <div class='archive js-post-feed'>
      {{#foreach posts visibility='all'}}
        <div
          class='archive-post-wrap post-year-{{date format='Y'}} js-post-card'
        >
          <div class='archive-post-label m-t m-b-sm fw-600'>{{date
              format='YYYY'
            }}</div>
          <article class='archive-post'>
            <time
              datetime='{{date published_at format='YYYY-MM-DD'}}'
              class='text-acc-3'
            >{{date published_at format='DD MMM YYYY'}}
            </time>

            <h2 class='archive-post__title fw-500 text-acc-2 m-0'>
              <a class='archive-post__link flex-1' href='{{url}}'>{{title}}</a>
            </h2>
          </article>
        </div>
      {{/foreach}}
    </div>

    {{! Pagination }}
    {{pagination}}
  </div>
</div>

First part of the code is the page title and then a small excerpt listing the number of posts in total using the pagination.total in the {{get "posts"}} context.

Next we have the posts, and note that in since we added the /archive/ to the routes and having the controller channel we don't need to fetch the posts using the {{get}} helper, as they will be available by default (paginated).

Within the {{foreach}} we have the layout of the post, which in this case has a post date and title, also some additional elements like the .archive-post-wrap and the .archive-post-label, these elements will be used to achieve grouping of posts by the year they were posted in.

Last part is the {{pagination}}, since we have a paginated content we have to offer the users the possibility to navigate though the pages of content. And the pagination helper will be the control for that.

For the grouping you can use css to not display the labels(beside the first one) until it's a different year, check out this thread on the forum for more details.

Final result

The second approach is part of Dashi Ghost Theme with a load more posts button instead of pagination.

Here is how it looks:

Tag Dropdown
Tag Dropdown

You can see it live on the Dashi Demo. I hope this was helpful.