Shopify-根据当前文章获得独特的文章';s标签

Shopify-根据当前文章获得独特的文章';s标签,shopify,liquid,Shopify,Liquid,我试图做到的是,当用户在一篇单独的博客文章/帖子上时,我希望根据匹配的标记显示唯一的“相关文章” 以下是我目前掌握的情况: {% for tag in article.tags %} {% assign counter = 0 %} {% for article in blog.articles %} {% if article.tags contains tag and counter < 2 %} {% assign counter = counter |

我试图做到的是,当用户在一篇单独的博客文章/帖子上时,我希望根据匹配的标记显示唯一的“相关文章”

以下是我目前掌握的情况:

{% for tag in article.tags %}

  {% assign counter = 0 %}
  {% for article in blog.articles %}
    {% if article.tags contains tag and counter < 2 %}
      {% assign counter = counter | plus: 1 %}
      <li class="well">
      {% if article.excerpt.size > 0 %}
          <div class="thumb-article">
              <a href="{{ article.url }}">
                  {{ article.excerpt }}
              </a>
          </div>
          {% endif %}
              <h3><a href="{{ article.url }}">{{ article.title }}</a></h3>
              <p>{{ article.content | strip_html | strip_newlines | truncatewords: 40 }}</p>
      </li>
    {% endif %}
  {% endfor %}

{% endfor %}
{%for article.tags%}
{%assign counter=0%}
{blog.articles%中的文章为%s}
{%如果article.tags包含标记和计数器<2%}
{%分配计数器=计数器|加:1%}
  • {%如果article.extracpt.size>0%} {%endif%} {{article.content | strip_html | strip_newlines | truncatewords:40}

  • {%endif%} {%endfor%} {%endfor%}
    令人惊讶的是,(对我来说,这是我第一次体验Shopify和liquid),它工作得有点太好了,因为它得到了重复的帖子


    有什么方法可以防止它得到重复的文章吗

    此线程具有您需要的内容:

    它创建一个空的relatedposts变量,然后在一个循环中定义它,该循环查看同一类别的其他帖子。重复其答案:

        {% assign related_posts = "" %}
    {% for article in blogs.blog.articles %}
      {% if article.tags contains product.handle %}
        {% capture post %}
          <li><a href="{{ article.url }}"><p>{{ article.title }}</p></a></li>
        {% endcapture %}
        {% assign related_posts = related_posts | append:post %}
      {% endif %}
    {% endfor %}
    {% if related_posts.size > 0 %}
      <ul> {{ related_posts }} </ul>
    {% else %}
      No related posts!
    {% endif %}
    
    {%assign related_posts=”“%}
    {blogs.blog.articles%中的文章为%s}
    {%如果article.tags包含product.handle%}
    {%capture post%}
    
  • {%endcapture%} {%assign related_posts=related_posts | append:post%} {%endif%} {%endfor%} {%if related_posts.size>0%}
      {{相关文章}
    {%else%} 没有相关的帖子! {%endif%}

    转到上面的链接查看完整响应。

    此线程具有您所需的内容:

    它创建一个空的relatedposts变量,然后在一个循环中定义它,该循环查看同一类别的其他帖子。重复其答案:

        {% assign related_posts = "" %}
    {% for article in blogs.blog.articles %}
      {% if article.tags contains product.handle %}
        {% capture post %}
          <li><a href="{{ article.url }}"><p>{{ article.title }}</p></a></li>
        {% endcapture %}
        {% assign related_posts = related_posts | append:post %}
      {% endif %}
    {% endfor %}
    {% if related_posts.size > 0 %}
      <ul> {{ related_posts }} </ul>
    {% else %}
      No related posts!
    {% endif %}
    
    {%assign related_posts=”“%}
    {blogs.blog.articles%中的文章为%s}
    {%如果article.tags包含product.handle%}
    {%capture post%}
    
  • {%endcapture%} {%assign related_posts=related_posts | append:post%} {%endif%} {%endfor%} {%if related_posts.size>0%}
      {{相关文章}
    {%else%} 没有相关的帖子! {%endif%}

    转到上面的链接查看完整响应。

    对于那些也在搜索如何将相关博客帖子发布到博客而非产品的人,如提供的链接中所示,上面的代码有修复程序:

    ...
    {% assign skip_articles = article.handle | split: '.....' %}
    ...
    {% for ...
        {% if ...
          {% unless skip_articles contains related_article.handle %}
            ...
            {% assign temp = related_article.handle | split: '.....' %}
            {% assign skip_articles = skip_articles | concat: temp %}
            ...
    
    按句柄中找不到的任何内容拆分以创建数组

    结果是这样的:

    <div class='relatedArticles'>
      {% for tag in article.tags %}
    
      {% assign counter = 0 %}
      {% assign skip_articles = article.handle | split: '.....' %}
      {% for related_article in blog.articles %}
        {% if related_article.tags contains tag and counter < 6 %}
          {% unless skip_articles contains related_article.handle %}
            {% assign counter = counter | plus: 1 %}
            {% assign temp = related_article.handle | split: '.....' %}
            {% assign skip_articles = skip_articles | concat: temp %}
            <div class="well">
              <h3><a href="{{ related_article.url }}">{{ related_article.title }}</a></h3>
              {% if related_article.excerpt.size > 0 %}
                <p>{{ related_article.excerpt }}</p>
              {% else %}
                <p>{{ related_article.content | truncatewords: 40 }}</p>
              {% endif %}
            </div>
          {% endunless %}
        {% endif %}
      {% endfor %}
    
      {% endfor %}
    </div>
    
    
    {article.tags%中标记的%s}
    {%assign counter=0%}
    {%assign skip_articles=article.handle | split:'..…'%}
    {blog.articles%}中的相关文章为%
    {%if related_article.tags包含标记和计数器<6%}
    {%除非skip_articles包含相关的_article.handle%}
    {%分配计数器=计数器|加:1%}
    {%assign temp=related_article.handle | split:'....'%}
    {%assign skip_articles=skip_articles | concat:temp%}
    {%if related_article.extracpt.size>0%}
    {{相关文章节选}

    {%else%} {{related_article.content}truncatewords:40}

    {%endif%} {%end除非%} {%endif%} {%endfor%} {%endfor%}
    对于那些也在搜索如何将相关博客帖子发布到博客而非产品的人,如提供的链接所示,上面的代码有修复程序:

    ...
    {% assign skip_articles = article.handle | split: '.....' %}
    ...
    {% for ...
        {% if ...
          {% unless skip_articles contains related_article.handle %}
            ...
            {% assign temp = related_article.handle | split: '.....' %}
            {% assign skip_articles = skip_articles | concat: temp %}
            ...
    
    按句柄中找不到的任何内容拆分以创建数组

    结果是这样的:

    <div class='relatedArticles'>
      {% for tag in article.tags %}
    
      {% assign counter = 0 %}
      {% assign skip_articles = article.handle | split: '.....' %}
      {% for related_article in blog.articles %}
        {% if related_article.tags contains tag and counter < 6 %}
          {% unless skip_articles contains related_article.handle %}
            {% assign counter = counter | plus: 1 %}
            {% assign temp = related_article.handle | split: '.....' %}
            {% assign skip_articles = skip_articles | concat: temp %}
            <div class="well">
              <h3><a href="{{ related_article.url }}">{{ related_article.title }}</a></h3>
              {% if related_article.excerpt.size > 0 %}
                <p>{{ related_article.excerpt }}</p>
              {% else %}
                <p>{{ related_article.content | truncatewords: 40 }}</p>
              {% endif %}
            </div>
          {% endunless %}
        {% endif %}
      {% endfor %}
    
      {% endfor %}
    </div>
    
    
    {article.tags%中标记的%s}
    {%assign counter=0%}
    {%assign skip_articles=article.handle | split:'..…'%}
    {blog.articles%}中的相关文章为%
    {%if related_article.tags包含标记和计数器<6%}
    {%除非skip_articles包含相关的_article.handle%}
    {%分配计数器=计数器|加:1%}
    {%assign temp=related_article.handle | split:'....'%}
    {%assign skip_articles=skip_articles | concat:temp%}
    {%if related_article.extracpt.size>0%}
    {{相关文章节选}

    {%else%} {{related_article.content}truncatewords:40}

    {%endif%} {%end除非%} {%endif%} {%endfor%} {%endfor%}
    您的链接已被密码锁定,因此我们无法查看。此代码对您有帮助吗?或者这样:@NathanielFlick似乎有效,我只希望他们能正确标记它们。哦,酷,哪个链接对你有效?你的链接被密码锁定了,所以我们看不到。这个代码对你有帮助吗?或者说:@NathanielFlick这似乎有效,我只希望他们能正确地标记它们。哦,酷,哪个链接对你有效?