按标签过滤 Ghost 博客相关帖子

get filter Ghost blog related posts by tag

我正在尝试使用 Ghost 博客中的 Get 帮助程序按标签获取相关帖子的列表。

我尝试按照 cookbook in Ghost docs 通过标签获取相关帖子,但似乎某些语法略有变化(我知道这是测试版功能!)。

但我在 post.hbs 上使用了它(在 {{#post}} 块内):

{{#get "posts" limit="4" include="tags" filter="tags.name:[Test]+posts.id:-{{id}}" as |related|}} 
{{!-- do appropriate stuff --}}
{{/get}}

明显的问题是 Test 标签在这里被硬编码了。尽管 {{tags}} 为我输出了标签列表,但它在这里不起作用:

App 22174 stderr: ERROR: Query Error: unexpected character in filter at char 11
App 22174 stderr: tags.name:[[object Object]]+pos
App 22174 stderr: -----------^
App 22174 stderr: Expecting 'NULL', 'TRUE', 'FALSE', 'NUMBER', 'LITERAL', 'STRING', got 'LBRACKET' 
App 22174 stderr:  Error parsing filter 
App 22174 stderr:  For more information on how to use filter, see http://api.ghost.org/docs/filter 

有人有什么想法吗?

PS 这是使用版本 0.11.7(我刚刚看到 0.11.8 最近发布了,但是 the changelog 没有注意到任何相关的内容)。

我在使用过滤器按标签获取相关帖子时也遇到了问题,我终于解决了。所以以防万一你没有,或者其他任何人可能会遇到这个......

我在解析过滤器时遇到问题。这是我现在使用为我工作的 get 助手的代码( 注意: 我的侧边栏在我的 {{#post}} 块中):

{{#get "posts" limit="3" filter="tags:[{{tags[*].slug}}]+id:-{{id}}" include="tags"}}
  {{#foreach posts}}
    <p>{{title}}</p>
  {{/foreach}}
{{/get}}

我的一个问题似乎是我的一些标签是 2 个单词,这意味着我必须引用标签的 slug(这就是 tags[*].slug 正在做的)。

我还有一个只有一个字母的标签(Ghost 自动将 C# 标签 slug 设为 c),过滤器也不喜欢这样。我将 slug 编辑为 c-sharp,现在一切正常。