Tags Jekyll和liquid-按相等标签的数量显示相关帖子>;=2.

Tags Jekyll和liquid-按相等标签的数量显示相关帖子>;=2.,tags,jekyll,liquid,Tags,Jekyll,Liquid,我想在每篇文章的底部添加一个名为“relatedposts”的栏,以及相关文章的标准和出现的标准,这两篇文章中至少有2个相等的标签 我目前的做法是: {% for tag in page.tags %} {% assign currentTag = tag | first %} {% for post in site.posts | limit:3 %} {% if post.tags contains currentTag | plus:1 %}

我想在每篇文章的底部添加一个名为“relatedposts”的栏,以及相关文章的标准和出现的标准,这两篇文章中至少有2个相等的标签

我目前的做法是:

{% for tag in page.tags %}

    {% assign currentTag = tag | first %}


    {% for post in site.posts | limit:3 %}
        {% if post.tags contains currentTag | plus:1 %}

        <div> 
        <a href="{{ post.url }}">
            <img src="{{site.baseurl}}/asset/img/{{ post.img-thumb }}">
        </a>
        <h5> {{ post.title }}</h5>
        </div>


        {% endif %}
    {% endfor %}

{% endfor %}
{%for page.tags%}
{%assign currentTag=tag | first%}
{%forpost in site.posts | limit:3%}
{%如果post.tags包含currentTag | plus:1%}
{{post.title}}
{%endif%}
{%endfor%}
{%endfor%}

谢谢你的帮助

此代码执行以下操作:

<div class="relatedPosts">

  <h3>Related post</h3>

  {% comment %}---> the maximum number of related to posts 
                    to be printed {% endcomment %}
  {% assign maxRelated = 5 %}

  {% comment %}---> the minimum number of common tags 
                    to have for a post to be considered 
                    as a related post {% endcomment %}
  {% assign minCommonTags =  3 %}

  {% assign maxRelatedCounter = 0 %}

  {% for post in site.posts %}

    {% assign sameTagCount = 0 %}
    {% assign commonTags = '' %}

    {% for tag in post.tags %}
      {% comment %}---> Only compare if post is 
                        not same as current page {% endcomment %}
      {% if post.url != page.url %}
        {% if page.tags contains tag %}
          {% assign sameTagCount = sameTagCount | plus: 1 %}
          {% capture tagmarkup %} <span class="label label-default">{{ tag }}</span> {% endcapture %}
          {% assign commonTags = commonTags | append: tagmarkup %}
        {% endif %}
      {% endif %}
    {% endfor %}

    {% if sameTagCount >= minCommonTags %}
      <div>
      <h5><a href="{{ site.baseurl }}{{ post.url }}">{{ post.title }}{{ commonTags }}</a></h5>
      </div>
      {% assign maxRelatedCounter = maxRelatedCounter | plus: 1 %}
      {% if maxRelatedCounter >= maxRelated %}
        {% break %}
      {% endif %}
    {% endif %}

  {% endfor %}

</div>

相关职位
{%comment%}->与帖子相关的最大数量
要打印的{%endcomment%}
{%assign maxRelated=5%}
{%comment%}->公共标记的最小数量
有一个职位需要考虑
作为相关帖子{%endcomment%}
{%assign minCommonTags=3%}
{%assign maxRelatedCounter=0%}
{site.posts%中的post为%s}
{%assign sameTagCount=0%}
{%assign commonTags=''%}
{post.tags%中标记的%s}
{%comment%}->仅当post为
与当前页面不同{%endcomment%}
{%if post.url!=page.url%}
{%如果page.tags包含标记%}
{%assign sameTagCount=sameTagCount | plus:1%}
{%capture tagmarkup%}{{tag}{%endcapture%}
{%assign commonTags=commonTags | append:tagmarkup%}
{%endif%}
{%endif%}
{%endfor%}
{%if sameTagCount>=minCommonTags%}
{%分配maxRelatedCounter=maxRelatedCounter |加:1%}
{%如果maxRelatedCounter>=maxRelated%}
{%break%}
{%endif%}
{%endif%}
{%endfor%}

编辑:为
maxRelated
minCommonTags
添加了“配置”,并添加了一项测试,以避免将帖子放入自己的相关帖子列表中。

顺便问一下:有人知道站点变量site.related\u帖子的标准是什么吗?