在Ghost JS中获取N个标记为T的最后帖子



我的问题。

我正在使用Ghost JS创建一个博客,在home.hbs页面中,我需要包含两个单独的摘要列表,其中包含我博客中发布的最新帖子。第一个列表应显示最近n1个带有标签t1的帖子,而第二个列表将显示最近n2个带有标签t2的帖子。例如,n1=8 t1=book应该代表get last 8 published books in my blogn2=3 t2=song代表get last 3 published songs in my blog

我的方法。

由于我不确定我的问题是否可以通过上下文和帮助程序以声明方式解决,因此我正在尝试激活 Beta 功能,并且正在使用 ghost 提供的 REST API。我已经阅读了 API 文档,但我不知道应该如何表达我的查询。我正在检查如下查询,但在表达过滤条件时失败(仅获取那些被T标记的帖子(:

jQuery(document).ready(function () {
    $.get(
       ghost.url.api('posts', {
          limit: '3',
          include: 'tags, author',
          filter: 'tags:song', // ???
          order: 'count.posts DESC'
       })
    ).done(onSuccess);
});

我的问题。

我的问题是双重的。是否有一些方法可以解决我的问题,以便使用上下文和帮助程序以声明性方式解决它?如果没有,我应该如何在对 API 的 AJAX 调用中对查询进行编码,以获取最后 N 个带有标签T的帖子?

您可以使用新的 {{get}} 帮助程序。

https://themes.ghost.org/docs/get

沿着这些思路的东西适用于标签云。

{{#get "tags" limit="3" include="count.posts" order="count.posts desc"}}

至于带有标签的帖子,您可以这样做。

{{#get "posts" limit="3" include="tags, author" filter="tag:song"}}

最新更新