Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jekyll 使用!=思维方式_Jekyll_Liquid - Fatal编程技术网

Jekyll 使用!=思维方式

Jekyll 使用!=思维方式,jekyll,liquid,Jekyll,Liquid,我正在使用Jekyll构建一个站点,并尝试使用Liquid logic在每篇文章的末尾创建一个“最近的帖子”数组 我希望此数组包含除您当前所在页面的帖子之外的所有帖子 因此,我从以下几点开始: {% for post in site.posts limit:2 %} {% if post.title != page.title %} //render the post {% endif %} {% endfor %} 这是有效的,除了我的限制:2导致问题。既然液体限制 代码>如

我正在使用Jekyll构建一个站点,并尝试使用Liquid logic在每篇文章的末尾创建一个“最近的帖子”数组

我希望此数组包含除您当前所在页面的帖子之外的所有帖子

因此,我从以下几点开始:

{% for post in site.posts limit:2 %}
  {% if post.title != page.title %}
    //render the post
  {% endif %}
{% endfor %}
这是有效的,除了我的
限制:2
导致问题。既然液体限制<强> <<强> >代码>如果逻辑,如果它遇到标题等于当前页面标题的帖子,它将(正确)不渲染它,但是它会考虑限制“满意”,而我只剩下1个相关的帖子而不是2。p> 接下来,我尝试创建自己的帖子数组:

{% assign currentPostTitle = "{{ page.title }}" %}
{% assign allPostsButThisOne = (site.posts | where: "title" != currentPostTitle) %}

{% for post in allPostsButThisOne limit:2 %}
  //render the post          
{% endfor %}
这不起作用,因为我无法让
where
过滤器接受
=逻辑


我如何才能成功绕过这个问题?

您可以使用计数器:

{% assign maxCount = 2 %}
{% assign count = 0 %}
<ul>
{% for post in site.posts %}
  {% if post.title != page.title and count < maxCount %}
    {% assign count = count | plus: 1 %}
    <li>{{ post.title }}</li>
  {% endif %}
{% endfor %}
</ul>
{%assign maxCount=2%}
{%assign count=0%}
    {site.posts%中的post为%s} {%if post.title!=page.title和count{{post.title}} {%endif%} {%endfor%}

您可以使用计数器:

{% assign maxCount = 2 %}
{% assign count = 0 %}
<ul>
{% for post in site.posts %}
  {% if post.title != page.title and count < maxCount %}
    {% assign count = count | plus: 1 %}
    <li>{{ post.title }}</li>
  {% endif %}
{% endfor %}
</ul>
{%assign maxCount=2%}
{%assign count=0%}
    {site.posts%中的post为%s} {%if post.title!=page.title和count{{post.title}} {%endif%} {%endfor%}

正如您所提到的,您只错过了以下代码:

{% assign allPostsButThisOne = (site.posts | where: "title" != currentPostTitle) %}
你试着用我的


正如您所提到的,您只错过了以下代码:

{% assign allPostsButThisOne = (site.posts | where: "title" != currentPostTitle) %}
你试着用我的


很好,这正是我所需要的——一种思考解决问题的新方法。非常感谢。很好,这正是我所需要的——一种思考解决问题的新方法。非常感谢。这种语法是错误的。一种标准的方法是:`{%assign allPostsButThisOne=(site.posts | where_exp:“item”,“item.title!='currentPostTitle')%}`inigomedina的语法几乎适用于我,我只需要删除语法错误的括号。一种标准的方法是:`{%assign allPostsButThisOne=(site.posts | where_exp:“item”,“item.title!='currentPostTitle')%}`inigomedina的语法几乎适用于我,我只需要去掉括号