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

推荐订阅源

P
Palo Alto Networks Blog
P
Proofpoint News Feed
GbyAI
GbyAI
Microsoft Azure Blog
Microsoft Azure Blog
B
Blog
Google DeepMind News
Google DeepMind News
N
Netflix TechBlog - Medium
Recorded Future
Recorded Future
M
MIT News - Artificial intelligence
罗磊的独立博客
J
Java Code Geeks
月光博客
月光博客
F
Full Disclosure
博客园 - 聂微东
人人都是产品经理
人人都是产品经理
U
Unit 42
WordPress大学
WordPress大学
A
About on SuperTechFans
C
Cyber Attacks, Cyber Crime and Cyber Security
SecWiki News
SecWiki News
Security Latest
Security Latest
C
Check Point Blog
C
CERT Recently Published Vulnerability Notes
小众软件
小众软件
I
InfoQ
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
B
Blog RSS Feed
V
Visual Studio Blog
博客园_首页
NISL@THU
NISL@THU
I
Intezer
Spread Privacy
Spread Privacy
AWS News Blog
AWS News Blog
The Register - Security
The Register - Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Latest news
Latest news
Project Zero
Project Zero
博客园 - 叶小钗
C
Cybersecurity and Infrastructure Security Agency CISA
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy International News Feed
博客园 - 【当耐特】
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Threat Research - Cisco Blogs
Simon Willison's Weblog
Simon Willison's Weblog
T
Tor Project blog
V
Vulnerabilities – Threatpost
博客园 - 司徒正美
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
雷峰网
雷峰网

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 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 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 Custom Navigation Template in Ghost
Bright Themes · 2023-10-01 · via Example blog

Little things can make a big difference. Your website navigation is a great example. The navigation structure and UX have a huge impact on conversions and bounce rates. Clear, hierarchical website navigation will help your visitors find what they want and provide a great user experience.

In Ghost CMS, you can define your menu items in the Admin area by going to Settings > Navigation There you have a primary and secondary navigation section, and these are rendered using a built-in helper {{navigation}}.

The navigation helper & properties

The {{navigation}} helper outputs a formatted HTML of menu items defined in the Ghost admin panel. the default navigation template:

<ul class='nav'>
  {{#foreach navigation}}
    <li class='{{link_class for=(url) class=(concat 'nav-' slug)}}'><a
        href='{{url absolute='true'}}'
      >{{label}}</a></li>
  {{/foreach}}
</ul>

As you can see some special attributes can be used within the {{#foreach navigation}} loop of this template to help with formatting. The available attributes:

  • {{label}} - The text to display for the link
  • {{url}} - The URL to link to
  • {{current}} - Boolean true / false - whether the URL matches the current page
  • {{slug}} - Slugified name of the page, eg contact-us.

Outside of the navigation helper, you have some global attributes to check whether there are any items defined:

{{#if @site.navigation}}
  {{! Render primary menu or button }}
{{/if}}

{{#if @site.secondary_navigation}}
  {{! Render secondary menu or button }}
{{/if}}

As you can see, Ghost uses the same template for both primary and secondary navigation, but it's possible to render them differently.

Changing the navigation template

In case you want to make a custom navigation layout, maybe a fixed menu, or you simply want to render it differently, then you have to overwrite the default template. This can be done by creating a new file in your theme in the partials directory called navigation.hbs. If such a file exists, Ghost will load it instead of the default template.

For a different secondary navigation you can add the following check in the template:

{{#if isSecondary}}
  {{! Template for secondary navigation }}
{{else}}
  {{! Template for primary navigation }}
{{/if}}

Modifying the {{navigation}} helper you are not limited to render only the items defined in the admin area, you can add any valid HTML to this template. An advanced use case would be adding a mega menu or dropdown menu for your site. Ghost doesn't support this feature, so the only possibility (without using javascript) would be to add the HTML markup in this template.

Adding icons to your navigation items

Another use case could be, if you want to add icons to your navigation items dynamically, as we did for our Dashi theme. What we need for this, before customizing the navigation helper, is to add an icon sprite(svg) to our Ghost theme. This SVG sprite has to contain all icons we need for our navigation items.

The code for the navigation would look like this:

{{#foreach navigation}}
  <li class='nav-{{slug}}' role='menuitem'>
    <a href='{{url}}'>
      <svg class='icon-svg'>
        <use xlink:href='{{asset "menu-icons.svg"}}#{{slug}}'></use>
      </svg>
    </a>
  </li>
{{/foreach}}

This code assumes you have a file named menu-icons.svg in the assets directory. (example of SVG sprite from feathericons) SVG sprites contains <symbol> elements with different ids.

Caution

Important is that your navigation items' slug has to match a symbol element id.

Make sure to check your menu slugs and create/rename the corresponding icons in your SVG.

Here is how the result looks in the Dashi theme:

Dashi Ghost - Menu Icons
Dashi Ghost - Menu Icons

This guide does not provide styling for the icons/svg so make sure you apply at least width and height for the .icon-svg class.