【问题标题】:Contentful JS API: Query for related articles with similar tags as the currently viewed article ? (article…tagList[])Contentful JS API:查询与当前查看的文章标签相似的相关文章? (文章…tagList[])
【发布时间】:2021-12-30 14:51:59
【问题描述】:

概述:

有人查看文章(内容类型:文章)。这篇文章有一个标签列表(contenttype : articletags)。

基于本文中的链接标签,我正在尝试对具有一个或多个相同标签的文章进行查询(将其称为具有相同标签的相关文章)。

结构如下:

let tags = article.items[0].fields.tagsList.map(tag => {
   return tag.fields.navn
})

我需要查询这样的文章:

contentful.getEntries({content_type: ‘article’}) ???

如何查询id?

【问题讨论】:

    标签: contentful contentful-api


    【解决方案1】:

    我认为您正在寻找的是 links_to 查询参数。

    通过这个,您可以找出哪些条目与另一个条目相关。

    client.getEntries({
      links_to_entry: '<entry_id>'
    })
    

    【讨论】:

      【解决方案2】:

      您可以使用 [in] 运算符来查询具有给定标签的条目。

          contentful
            .getEntries({
              content_type: "article",
              'fields.tags':  "website" , //tag id = website
            })
            .then(({ items }) => {
              console.log(items);
            })
            .catch(console.error);
      

      参考:https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/inclusion

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-09-14
        • 1970-01-01
        • 1970-01-01
        • 2012-11-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多