跳过上一篇文章时如何忽略jekyll中的偏移 [英] How to ignore offset in jekyll when previous post is skipped

查看:86
本文介绍了跳过上一篇文章时如何忽略jekyll中的偏移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在jekyll上创建我的第一个博客.我陷入了一件愚蠢的事情. 所以主题是下一个: 我有一个类别用于我的类别之一,让它成为新闻":

i'm trying to create my first blog on jekyll. And i stucked in one stupid thing. so the theme is next: i have a section for one of my categories, let it be "news":

<section class="news">
    <div class="container">
        <div class="row no-gutters">

{% for post in site.categories.news limit: 2 offset: 0 %} 
{% include news-item-col-6.html %}
{% endfor %}

{% for post in site.categories.news limit: 3 **offset: 2** %}
{% include news-item-col-4.html %}
{% endfor %}

        </div>
    </div>
</section>

news-item-col-6:

news-item-col-6:

{% if post.thumb != 0 %}
   <div class="col-md-6">
        <div class="pattern">
            <div class="overlay item-title" style="background-image: url({{ post.thumb }});">               
                <div class="item-title-content">
                    <h3><a href="{{ post.url }}">{{ post.header }}</a></h3>                     
                </div>
            </div>      
        </div>
    </div>
{% endif %}

news-item-col-4:

news-item-col-4:

{% if post.thumb != 0 %}
  <div class="col-md-4">
    <div class="pattern">           
        <div class="overlay item-title" style="background-image: url({{ post.thumb }});">
            <div class="item-title-content">
                <h3><a href="{{ post.url }}">{{ post.header }}</a></h3>                 
            </div>
        </div>                  
    </div>
  </div>
{% endif %}

我的帖子tp

my posts tp

---
layout: post
title: title | site.com
header: title
description: discription
categories: categories url
catname: News
image: "images/URL /to image/1.jpg"
thumb: "images/URL /to thumb/1t.jpg"
permalink: "blog/:categories/:year-:month-:day-:slug.html"
---

所以问题在于,并非我所有的帖子都具有背景经验,而我要做的就是忽略没有{post.thumb}的帖子.并且代码是可行的,但是不幸的是col-md-4块的偏移量没有忽略没有post.thumb的post的顺序.

so the problem is that not all of my posts will have background thumb, and all i want to do is to ignore the posts wich has no {post.thumb}. and the code is works, but unfortunately col-md-4 block's offset is not ignoring post's order with no post.thumb.

在下面的不适中尝试解释我想要的东西:

in picture bellow ill try to explain what i want:

如果我所有的帖子都贴有post.thumb(bg_image) a>

如果我的帖子Item2没有post.thumb(bg_image),这应该是这样只是没有出现在

这就是我的代码的工作方式:D

那么应该怎么做才能使其正常工作?

so what a should do to make it works right?

P.S.我的英语很差,所以我为语法错误感到抱歉,我恳求你们给出尽可能简单的答案...

P.S. My english is bad enough, so im sorry for grammar mistakes and i`m assking u guys to give answers as much simpple as u can do...

推荐答案

只需使用一个自定义计数器,如下所示:

Just use a custom counter, like this:

{% assign counter = 0 %} <!-- create a custom counter and set it to zero -->
{% for post in site.categories.news %} <!-- loop through the posts in news -->
  {% if post.thumb %} <!-- check if the post has a thumbnail -->
    {% assign counter = counter | plus: 1 %} <!-- increment the counter if it does -->
    {% if counter < 3 %} <!-- if this is the first or second counted post -->
      {% include news-item-col-6.html %} <!-- include the col-6 element -->
    {% elsif counter < 6 %} <!-- else -->
      {% include news-item-col-4.html %} <!-- include the col-4 element -->
    {% endif %}
  {% endif %}
{% endfor %}

这篇关于跳过上一篇文章时如何忽略jekyll中的偏移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆