Looping Previous and Next Post in Jekyll -


my jekyll based portfolio lists projects in chronological order. i'm using page.previous , page.next display next , previous posts in portfolio. when there no 'previous' or 'next' project, there's giant empty space.

how can modify:

<section id="more-work">     {% if page.previous %}     <div class="left">         <a class="equalize" href="{{page.previous.url}}" title="previous post: {{page.previous.title}}">             <div>                 <h6> ← previous project </h6>                 <h4> {{page.previous.title}} </h4>             </div>         </a>     </div>     {% endif %} {% if page.next %}     <div class="right">         <a class="equalize" href="{{page.next.url}}" title="next post: {{page.next.title}}">             <div>                 <h6> next project →</h6>                 <h4> {{page.next.title}}</h4>             </div>           </a>     </div>     {% endif %} </section> 

...so loops on end of list or beginning of list?

this can job :

<section id="more-work">     {% if page.previous %}         {% assign previous = page.previous %}     {% else %}         {% assign previous = site.posts[0] %}     {% endif %}     <div class="left">         <a class="equalize" href="{{site.baseurl}}{{previous.url}}" title="previous post: {{previous.title}}">             <div>                 <h6> ← previous project </h6>                 <h4> {{previous.title}} </h4>             </div>         </a>     </div>      {% if page.next %}         {% assign next = page.next %}     {% else %}         {%comment%}            array index start @ 0 substract 1 total count,            last post index in site.posts array         {%endcomment%}         {% assign last lastpostindex = site.posts | size | minus: 1 %}         {% assign next = site.posts[lastpostindex] %}     {% endif %}     <div class="right">         <a class="equalize" href="{{site.baseurl}}{{next.url}}" title="next post: {{next.title}}">             <div>                 <h6> next project →</h6>                 <h4> {{next.title}}</h4>             </div>         </a>     </div> </section> 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -