Ghost:在首页上有特定标签的最新帖子 [英] Ghost: newest post with specific tag on the front page

查看:146
本文介绍了Ghost:在首页上有特定标签的最新帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的博客开发一个Ghost模板。我希望在首页上看到来自具有特定标签的帖子的最新帖子(例如新闻)。

是否可以通过 foreach 循环中的标记过滤帖子?



其他解决方案? (首先想到的是使用自定义模板 tag-news.hbs 和URL重写的一些技巧)

解决方案

您可以使用 {{has}} 助手来标记过滤帖子:

  {{#foreach posts}} 
{{#has tag =news}}
{{>

$ {$ / $ p $ b $ {$ / $ p

$ b $ { p>您可以将此代码添加到 home.hbs 文件中,并且只能在您的主页上使用。

如果您希望其他列表页面拥有多个帖子,我不确定将其限制为一个帖子的最佳方式。你可能不得不写一个自定义帮手。

您可以访问 @index 变量,但如果第一篇文章是'news'是第三篇后, @index 将会是 2 ,因为它会随着外部 foreach loop。



不久,您应该可以使用api: https://github.com/TryGhost/Ghost/wiki/%5BWIP%5D-API-Documentation


I am developing a Ghost template for my blog. And I want to see on the front page only one newest post from posts with specific tag (eg "news").

Is it possible to filter posts by tag in foreach loop?

Any other solution? (the first thing that comes to mind is some trick with custom template tag-news.hbs and URL rewriting)

解决方案

You can definitely filter posts by tag using the {{has}} helper:

{{#foreach posts}}
  {{#has tag="news"}}
      {{> post}}
  {{/has}}
{{/foreach}}

You could add this code to a home.hbs file and it would only be used on your homepage.

I'm not sure of the best way to limit it to one post if you want other list pages to have more than one post though. You may have to write a custom helper.

You do have access to an @index variable, but if the first post with 'news' is the third post, @index will be 2 because it increments with the outer foreach loop.

Soon you should be able to use the api: https://github.com/TryGhost/Ghost/wiki/%5BWIP%5D-API-Documentation

这篇关于Ghost:在首页上有特定标签的最新帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆