2017-02-23 2 views
0

업데이트 됨 : 이벤트 컬렉션이 있습니다. 이 컬렉션의 각 항목에는 날짜 시간 형식 (예 : 2017-02-23 00:05:09 +0700)으로 입력되는 맞춤 메타 '시작 시간 및 날짜 :'가 있습니다. 홈 레이아웃에서는 "시작 시간 및 날짜 :"가 오늘 날짜와 일치하는 이벤트 만 나열합니다. 오늘 날짜 만 (하지 홈 화면에 렌더링 목록) 시스템에 대한 사람들의 순서와 일치 이벤트의 결과리스트에배열의 다음/이전 항목 가져 오기 사용자 정의 프런트 매터순으로 정렬 된 날짜는 오늘 날짜와 일치하는 경우에만

{% assign events = site.events | sort: 'Start time and date' %} 
{% for event in events %} 
    {% assign today = site.time | date: "%b %d" %} 
    {% assign eventdate = event['Start time and date'] | date: "%b %d" %} 
    {% if eventdate == today %} 
    ... 
    {% else %} 
    {% endif %} 
{% endfor %} 

은 기본 page.date 아니라 이벤트 [ '를 시작으로 정렬됩니다 시간 및 날짜 ']. 내가 이벤트 페이지 내에 위치하고 page.next를 호출하면 오늘 생성 된 일일 이벤트 목록에서 다음 이벤트가 아니라 다음 이벤트 페이지 인 page.next가 모든 이벤트 (나는 그들이 날짜별로 분류된다고 가정한다).

기본 event.date가 아닌 내 맞춤 메타 이벤트 [ '시작 시간 및 날짜']를 사용하여 현재 이벤트를 기준으로 다음 이벤트 및 이전 이벤트에 액세스하려면 어떻게해야합니까? 기본적으로 오늘 날짜로 이전 이벤트를 가져옵니다.

제발 지루한 지식을 가지고 다녔습니다.

+0

메타 값에 공백이있을 수 있다고 생각하지 않습니다. 그러면 사용시 액체 구문 오류가 발생합니다. –

+0

{{post [ '공백이있는 메타 이름]}}으로 호출하면됩니다. – ntnlbd

답변

0

그래서 난이 방법으로 해결 할 수 있었다 오랜 투쟁 후, 아마도 누군가가 = 그것을 정돈이의 편집을 할 수있는 경우) 그래서 난 감사하겠습니다

을이 작업을 수행 할 수있는 쉽고 청소기 방법이
{% assign today = site.time | date: "%d" %} // find current date 
{% assign allevents = site.events | sort: 'Start time and date' %} // sort all items in collections event by custom metafield similar to the standard date field 

{% for event in allevents %} // loop through all events 
{% assign eventdate = event['Start time and date'] | date: "%d" %} // assign event date from the custom meta in the event item 
{% if eventdate == today %} // check if event date equals today 
    {% if event.url == page.url %} // check if event url is also currently generated page url 

     {% assign preveventindex = forloop.index | plus: 1 %} // find the index of previous event in the array 
     {% assign nexteventindex = forloop.index | minus: 1 %} // find the index of next event in the array 

     {% for event in allevents %} // loop throug events again 
     {% assign today = site.time | date: "%d" %} // set current date again 
     {% assign eventdate = event['Start time and date'] | date: "%d" %} // set event date again 

     {% if eventdate == today %} // check if event generated has current date 
      {% if forloop.index == nexteventindex %} // check if next event index is correct 

      {{ forloop.index }} - 
      {{ event.url }} 
      {% assign nexteventurl = event.url %} // get the url is next item in the array has the same date as current item 

      // You can now use the url to navigate to the next item in the array that must have todays date 

     {% endif %} 

     {% if forloop.index == preveventindex %} 
      {{ forloop.index }} - 
      {{ event.url }} 
      {% assign preveventurl = event.url %} 

      // You can now use the url to navigate to the previous item in the array that must have todays date 

     {% endif %} 
     {% endif %} 
    {% endfor %} 

    {% endif %} 
{% endif %} 
{% endfor %} 
관련 문제