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

推荐订阅源

S
Secure Thoughts
S
SegmentFault 最新的问题
云风的 BLOG
云风的 BLOG
T
Tailwind CSS Blog
博客园 - 聂微东
小众软件
小众软件
J
Java Code Geeks
MyScale Blog
MyScale Blog
人人都是产品经理
人人都是产品经理
量子位
GbyAI
GbyAI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
M
MIT News - Artificial intelligence
Apple Machine Learning Research
Apple Machine Learning Research
有赞技术团队
有赞技术团队
月光博客
月光博客
B
Blog RSS Feed
D
DataBreaches.Net
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Cyberwarzone
Cyberwarzone
I
Intezer
The Register - Security
The Register - Security
博客园 - 【当耐特】
博客园 - 司徒正美
L
Lohrmann on Cybersecurity
U
Unit 42
N
News and Events Feed by Topic
S
Security Affairs
V
Visual Studio Blog
Y
Y Combinator Blog
Security Latest
Security Latest
Know Your Adversary
Know Your Adversary
Google DeepMind News
Google DeepMind News
大猫的无限游戏
大猫的无限游戏
S
Schneier on Security
P
Privacy International News Feed
TaoSecurity Blog
TaoSecurity Blog
Spread Privacy
Spread Privacy
G
Google Developers Blog
NISL@THU
NISL@THU
Project Zero
Project Zero
P
Palo Alto Networks Blog
Help Net Security
Help Net Security
宝玉的分享
宝玉的分享
Stack Overflow Blog
Stack Overflow Blog
S
Security @ Cisco Blogs
G
GRAHAM CLULEY
www.infosecurity-magazine.com
www.infosecurity-magazine.com

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 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 a Featured Post Slider in Ghost
Bright Themes · 2023-02-15 · via Example blog

Having a featured post section on the homepage is a good way to highlight some of your content and with the featured flag in the post settings it's very easy to do.

But this needs some adjustment within your theme and more specifically you have to edit your index.hbs or home.hbs file.

Let's start with a simple scenario and simply get a list of featured posts and render it before the rest of the posts:

{{! Featured posts }}
{{#get 'posts' filter='featured:true' limit='all' as |featured|}}
  {{#foreach featured visibility='all'}}
    <h2><a href='{{url}}'>{{title}}</a></h2>
  {{/foreach}}
{{/get}}

In the above code block the following happens:

  • the {{get}} helper is used to fetch the list of featured posts using the filter attribute
  • in this case all featured posts will be fetched but you can also set a limit using the limit attribute
  • using the {{foreach}} helper we loop through all the posts and render the post title
  • you can extend this with other attributes within the post context such as date, author ( here is the full list of post attributes

To move this section to the top of the page, you have to add this code block before the other posts are displayed. This depends on your current setup, but generally it should be in the first part of your index.hbs file.

Now let's see a more specific scenario where we will create a slider/carousel out of the featured posts. For this we will use a library called Tiny Slider.

We have to include the tiny-slider script and css for this to work and the easiest way is to include it using a CDN. For this you can add the following in Code Injection:

<script
  src='https://cdnjs.cloudflare.com/ajax/libs/tiny-slider/2.9.3/min/tiny-slider.js'
  integrity='sha512-D/zaRVk05q6ERt1JgWB49kL6tyerY7a94egaVv6ObiGcw3OCEv0tvoPDEsVqL28HyAZhDd483ix8gkWQGDgEKw=='
  crossorigin='anonymous'
></script>
<link
  rel='stylesheet'
  href='https://cdnjs.cloudflare.com/ajax/libs/tiny-slider/2.9.3/tiny-slider.css'
  integrity='sha512-eMxdaSf5XW3ZW1wZCrWItO2jZ7A9FhuZfjVdztr7ZsKNOmt6TUMTQgfpNoVRyfPE5S9BC0A4suXzsGSrAOWcoQ=='
  crossorigin='anonymous'
/>

Another possibility to integrate this in your Ghost theme development setup, we use gulp as a task runner so it's possible to install tiny slider as a dependency and integrate it in the normal theme workflow. (if you feel comfortable enough with gulp and javascript)

Next step is to fetch the featured posts again and this time include the post image in the rendered template (you can add other properties from the post context as well).

{{! Featured posts }}
{{#get 'posts' filter='featured:true' limit='all' as |featured|}}
  <div class='featured-feed js-featured-feed'>
    {{#foreach featured visibility='all'}}
      <div class='featured-card'>
        {{! Feature Image }}
        {{#if feature_image}}
          <a
            class='featured-card__media m-b-sm'
            href='{{url}}'
            title='{{title}}'
            aria-label='{{title}}'
          >
            <img
              class='lazyload'
              data-srcset='{{img_url feature_image size='s'}} 300w,
                      {{img_url feature_image size='m'}} 600w'
              srcset='data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=='
              data-sizes='auto'
              data-src='{{img_url feature_image size='s'}}'
              src='{{img_url feature_image size='xxs'}}'
              alt='{{title}}'
            />
          </a>
        {{/if}}

        {{! Post Title }}
        <h2 class='fw-600 m-b-0 text-acc-1 text-xl'>
          <a href='{{url}}' aria-label='{{title}}'>{{title}}</a>
        </h2>
      </div>
    {{/foreach}}
  </div>
{{/get}}

This code will fetch the featured posts and then display the feature image and the title for all those posts.

The last step is to initialize the library. Include the following lines right after the closing {{/get}} tag:

{{#contentFor 'scripts'}}
  <script>
    const sliderContainer = document.querySelector('.js-featured-feed'); if
    (sliderContainer) { const slider = tns({ container: sliderContainer, items:
    3, slideBy: 1, loop: true, autoplay: false, gutter: 32, nav: true,
    responsive: { 0: { items: 1, }, 768: { items: 2, }, 992: { items: 3, } } });
    }
  </script>
{{/contentFor}}
  • the {{#contentFor}} tag will put the content within it in the {{{block "scripts"}}} which normally should be in the default.hbs file, towards the end. (more about the block helper)
  • the sliderContainer is needed for the tiny slider setup (it's the element containing all the posts)
  • tns is the slider itself, when we want to initialize it, we have to provide options like:
    • items - how many items should be displayed
    • autoplay - whether the plugin will automatically slide the elements
    • gutter - the spacing between the elements
    • responsive - you can set breakpoints to display items based on the device (in the case above on mobile only one item is displayed and as the viewport grows 2 or even three items are displayed)

There are much more options available to tweak the library behavior. ⟶ List of options

Result and Demo

Now your featured slider should be ready and integrated in your Ghost theme. In our Dashi theme we have this plugin integrated and styled.

Here is the result:

Featured Slider
Featured Slider

See it live