Created
September 7, 2018 21:40
-
-
Save edwardhorsford/370a4060a5a6dcd92e687fc824c5cdc5 to your computer and use it in GitHub Desktop.
Hacky next / previous code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% set currentProjectIndex = 0 %} | |
{% set countOfProjects = collections.design.length %} | |
{% for project in collections.design %} | |
{% if project.url == page.url %} | |
{% set currentProjectIndex = loop.index0 %} | |
{% endif %} | |
{% endfor %} | |
{% set previousProjectIndex = currentProjectIndex - 1 %} | |
{% set nextProjectIndex = currentProjectIndex + 1 %} | |
{% set previousProject = collections.design[previousProjectIndex] %} | |
{% set nextProject = collections.design[nextProjectIndex] %} | |
{% if previousProject %} | |
<p>Previous project: <a href="{{ previousProject.url | url }}" class="">{{ previousProject.data.title }}</a></h2> | |
{% endif %} | |
{% if nextProject %} | |
<p>Next project: <a href="{{ nextProject.url | url }}" class="">{{ nextProject.data.title }}</a></h2> | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment