【问题标题】:shopify return articles with same tags as current articleshopify 返回与当前文章标签相同的文章
【发布时间】:2015-02-15 19:39:50
【问题描述】:

我希望创建一个“类似文章”部分,它返回所有标签与当前文章相同的文章。

这是我目前所拥有的:

{% if article.tags.size > 0 %}
{% assign search_tag = {article.tags | join: ' , ' } %}
{% endif %}

    {% for article in blogs.news.articles limit:settings.sidebar_recent_artcie %}
        {% if article.tags contains {search_tag} %}
             <li><a href="{{ article.url }}">{{ article.title }}</a><br /><small>posted on {{ article.published_at | date: '%b %d, %Y' }}</small></li>
        {% endif %}
    {% endfor %}

这适用于文章包含 1 个标签的情况,所以我猜“包含”只能在标签列表中搜索整个 {search_tag} 字符串。

谢谢!

克里斯

【问题讨论】:

    标签: tags blogs shopify liquid


    【解决方案1】:

    您可能希望将搜索标签拆分为一个数组,而不是使用逗号分隔的字符串,然后在文章中搜索标签,以每个单词为基础进行包含。如果全部匹配,你就会知道。将 search_tags 保存为这样的字符串:“foo,buzz,bizz”并在标签上使用 contains,它们存储为字符串,但实际上是一个数组,这可能是您的问题。那么按照以下方式进行检查可能会更好吗?

    - "foo, buzz, bizz" contains "foo"?
    - "foo, buzz, bizz" contains "buzz"?
    - "foo, buzz, bizz" contains "bizz"?
    

    宾果?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-14
      • 2021-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多